Sunday, May 11, 2014

QTP &VB Script code to Send SMS using Way2sms to excel stored numbers and msgs

option explicit
Dim oex, owb, ows, mno, msg, x, ns, i

'goto excel sw
        Set oex=createobject("Excel.Application")
        oex.Visible=true
'goto workbook
        Set owb=oex.Workbooks.Open("F:\Book1")
'goto worksheet
Set ows=owb.Worksheets("Sheet2")
ns=ows.usedrange.rows.count

'launch way2sms
         systemutil.Run("www.way2sms.com")

'login
With browser ("title:=Free SMS.*")
With .page("title:=Free SMS.*")
.webedit("name:=username").set "Mobile Number"
.webedit("name:=password").set "Password"
.webbutton("name:=Login").click
End With
End With

'continue loop until last row
For i=2 to ns step 1
mno=ows.cells(i,1) 'retrive mobile number
msg=ows.cells(i,2) 'retrive msg to send

'click send  FREE sms link
With browser("title:=Free SMS.*")
With .page("title:=Free SMS.*")
.webelement("html tag:=DIV","index:=12").Click
End With
End With

'click send sms
With browser("title:=Free SMS.*")
With .page("title:=Free SMS.*")
.link("html tag:=A","index:=52").Click
End With
End With

'fill fields to send sms
With browser("title:=Free SMS.*")
With .page("title:=Free SMS.*")
.webedit("value:=Mobile Number").Set mno
.webedit("name:=textArea").Set msg
.webbutton("name:=Send SMS").Click
End With
End With

'validating sms status
With browser ("title:=Free SMS.*")
With .page("title:=Free SMS.*")
With .frame ("name:=frame")
x=.webelement("html tag:=DIV","index:=9").GetROProperty("innertext")

If trim(x)="Message has been submitted successfully" Then
ows.cells(i,3)="Test passed"
Else
ows.cells(i,3)="Test Failed"
End If

End With
End With
End with
Next

'signout
With browser("title:=.*")
With .page("title:=.*")
            .webelement("html id:=logoutBTN").Click
                    End With
End With

'close browser
browser("title:=.*").Close

'handle popup adds
If browser("title:=.*").Exist Then
browser("title:=.*").Close
End If

'auto fit rows & clmns
ows.rows.autofit
ows.columns.autofit

'save & close
owb.Save
  oex.Quit

'destroy object
  Set ows=nothing
  Set owb=nothing
  Set oex=nothing

2 comments:

  1. Hi, Thanks for the good piece of code.
    Can you please tell me how you found the index.
    I am able to find index using recording and Object repo, but not with descriptive program.Please tell me to find index by writing descriptive code

    ReplyDelete
    Replies
    1. http://myqtplessions.blogspot.in/2014/06/to-find-out-index.html

      thank you

      Delete