Visit: www.gcreddy.
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("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
  For i=0 to objColl.count-1 step 1
  objShell.SendKeys "{DOWN}"
  strName=objColl(i).getroproperty("innertext")
  Reporter.ReportEvent micDone,"Google Search Item
"&strName,"Item captured"
  Next
Set objDev=Nothing
Set objShell=Nothing
 1
 Visit: www.gcreddy.com for QTP Information
2) How to display dialog box and close it during runtime
x="sai"
y="SAI"
Set objShell=Createobject("Wscript.shell")
If strcomp(x,y,1)=0 Then
' msgbox "Both are equal"
objShell.Popup "Both are equal",5,"Gcreddy DialogBox"
else
' msgbox "Both are not equal"
objShell.Popup "Both are not eual",5,"Gcreddy DialogBox"
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
For i=0 to objColl.count-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
  Reporter.ReportEvent micPass,"Link Name  "&strName,"Link
Validation done"
 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
  objsheet.cells(i+2,4)="Link Validation done"
  Set c5= objsheet.cells(i+2,4)
  c5.font.color=vbGreen
  Else
      Reporter.ReportEvent micFail,"Link Name   "&strName,"Link
validation fail"
   objSheet.cells(i+2,1)=strName
   objsheet.cells(i+2,2)=TargetUrl
     objsheet.cells(i+2,3)=ActualUrl
  objsheet.cells(i+2,4)="Link Validation fail"
  Set c5= objsheet.cells(i+2,4)
  c5.font.color=vbRed
  End If
Browser("title:=.*").Back
Next
Set objWbook=objExcel.ActiveWorkbook
objWbook.SaveAs "E:\gcreddy.xls"
 objExcel.Quit
 Set objExcel=nothing