Thursday, November 20, 2008

QTP Script 17 - How to get link names and URLs for all the links on a web page?

For getting link names and URLs for each of the links it counted in Previous Script [Counting Total Links on a Web page]

If you have not seen the previous script, for your information you have to open www.google.com and write the below script in a new test and run it. It will show the link names and URLs in a messagebox one by one. You can move the results directly to the excel file also (take help from QTP Script 9 and 15).

Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col = Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
a= link_col.count

For i=0 to a-1
tag = link_col(i).GetROProperty("name")
href = link_col(i).GetROProperty("url")
msgbox tag &" " & href
Next