Visit: [Link].
com for QTP Information
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("[Link]")
[Link] x,y,LEFT_MOUSE_BUTTON 'To place mouse the
cursor in the edit box
Set objShell=Createobject("[Link]")
[Link] "QTP" 'To send data from keyboard"
wait(5)
Set objDesc=[Link]
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 [Link]
For i=0 to [Link]-1 step 1
[Link] "{DOWN}"
strName=objColl(i).getroproperty("innertext")
[Link] micDone,"Google Search Item
"&strName,"Item captured"
Next
Set objDev=Nothing
Set objShell=Nothing
1
Visit: [Link] for QTP Information
2) How to display dialog box and close it during runtime
x="sai"
y="SAI"
Set objShell=Createobject("[Link]")
If strcomp(x,y,1)=0 Then
' msgbox "Both are equal"
[Link] "Both are equal",5,"Gcreddy DialogBox"
else
' msgbox "Both are not equal"
[Link] "Both are not eual",5,"Gcreddy DialogBox"
End If
3) Create script for links validation and set results into an excel
file
Set objDesc=[Link]
objDesc("micclass").value="Link"
Set
objColl=Browser("title:=.*").page("title:=.*").ChildObjects(objDesc)
msgbox [Link]
Set objExcel=Createobject("[Link]")
[Link]=True
[Link]
set objSheet=[Link]
[Link](1,1)="LinkName"
2
Visit: [Link] for QTP Information
set c1=[Link](1,1)
[Link]=vbBlue
[Link](1,2)="TargetUrl"
Set c2=[Link](1,2)
[Link]=vbBlue
[Link](1,3)="ActualUrl"
Set c3=[Link](1,3)
[Link]=vbBlue
[Link](1,4)="Status"
Set c4=[Link](1,4)
[Link]=vbBlue
For i=0 to [Link]-37 step 1
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
If instr (1,TargetUrl,ActualUrl,1) > 0 Then
[Link] micPass,"Link Name "&strName,"Link
Validation done"
3
Visit: [Link] for QTP Information
[Link](i+2,1)=strName
[Link](i+2,2)=TargetUrl
[Link](i+2,3)=ActualUrl
[Link](i+2,4)="Link Validation done"
Set c5= [Link](i+2,4)
[Link]=vbGreen
Else
[Link] micFail,"Link Name "&strName,"Link
validation fail"
[Link](i+2,1)=strName
[Link](i+2,2)=TargetUrl
[Link](i+2,3)=ActualUrl
[Link](i+2,4)="Link Validation fail"
Set c5= [Link](i+2,4)
[Link]=vbRed
End If
Browser("title:=.*").Back
Next
Set objWbook=[Link]
[Link] "E:\[Link]"
[Link]
Set objExcel=nothing