QTP Script
QTP Script
QTP Scripts
1) How to get google search items
Dim x,y,objDev,objShell,objDesc,objColl,i,strName
x=Browser("Google").Page("Google").WebEdit("q").GetROProperty("ab
s_x")
y=Browser("Google").Page("Google").WebEdit("q").GetROProperty("ab
s_y")
Set objDev=Createobject("mercury.devicereplay")
objDev.MouseClick x,y,LEFT_MOUSE_BUTTON 'To place mouse the
cursor in the edit box
Set objShell=Createobject("wscript.shell")
objShell.SendKeys "QTP" 'To send data from keyboard"
wait(5)
Set objDesc=Description.Create
objDesc("micclass").value="WebElement"
objDesc("name").value="Google Search"
set
objColl=Browser("Google").Page("Google").WebTable("quotes").ChildO
bjects(objDesc) 'To get webelements in the webtable
msgbox objColl.count
Set objDev=Nothing
Set objShell=Nothing
1
Visit: www.gcreddy.com for QTP Information
y="SAI"
Set objShell=Createobject("Wscript.shell")
If strcomp(x,y,1)=0 Then
else
End If
3) Create script for links validation and set results into an excel
file
Set objDesc=Description.Create
objDesc("micclass").value="Link"
Set
objColl=Browser("title:=.*").page("title:=.*").ChildObjects(objDesc)
msgbox objColl.count
Set objExcel=Createobject("Excel.application")
objExcel.Visible=True
objExcel.Workbooks.Add
set objSheet=objExcel.ActiveSheet
objSheet.cells(1,1)="LinkName"
2
Visit: www.gcreddy.com for QTP Information
set c1=objSheet.cells(1,1)
c1.font.color=vbBlue
objSheet.cells(1,2)="TargetUrl"
Set c2=objSheet.cells(1,2)
c2.font.color=vbBlue
objSheet.cells(1,3)="ActualUrl"
Set c3=objSheet.cells(1,3)
c3.font.color=vbBlue
objSheet.cells(1,4)="Status"
Set c4=objSheet.cells(1,4)
c4.font.color=vbBlue
strName=Browser("title:=.*").page("title:=.*").Link("index:="&i).Get
RoProperty("name")
TargetUrl=Browser("title:=.*").page("title:=.*").Link("index:="&i).Ge
tRoProperty("url")
msgbox TargetUrl
Browser("title:=.*").page("title:=.*").Link("index:="&i).click
wait(4)
ActualUrl=Browser("title:=.*").GetRoProperty("url")
msgbox ActualUrl
3
Visit: www.gcreddy.com for QTP Information
objSheet.cells(i+2,1)=strName
objsheet.cells(i+2,2)=TargetUrl
objsheet.cells(i+2,3)=ActualUrl
c5.font.color=vbGreen
Else
objSheet.cells(i+2,1)=strName
objsheet.cells(i+2,2)=TargetUrl
objsheet.cells(i+2,3)=ActualUrl
c5.font.color=vbRed
End If
Browser("title:=.*").Back
Next
Set objWbook=objExcel.ActiveWorkbook
objWbook.SaveAs "E:\gcreddy.xls"
objExcel.Quit
Set objExcel=nothing