We need to use the ChildObjects method to get the collection of links. Using the collection object we can then retrieve the name and URL properties of every link.
Step by Step illustration:
1) Using the ChildObjects method, get all the links on the webpage.
2) We now have the collection object ready.
3) Use the GetROProperty method to retrieve the required property values. (In our case Innertext & href)
Example :
Click here for more QTP code snippets.
Step by Step illustration:
1) Using the ChildObjects method, get all the links on the webpage.
2) We now have the collection object ready.
3) Use the GetROProperty method to retrieve the required property values. (In our case Innertext & href)
Example :
' This can be used on any page Set oLinkDesc = Description.Create() ' Retrieve HTML tag "A" oLinkDesc("html tag").Value = "A" ' Create the collection object Set nLinksCollection = Browser("title:=.*"”).Page("title:=.*").ChildObjects(oLinkDesc) nLinksCount = nLinksCollection.Count() ' Retrieve all the requied properties For i=0 to nLinksCount-1 sName = nLinksCollection(i).GetROProperty("innertext") sHref = nLinksCollection(i).GetROProperty("href"”) ' Saving the results in the reporter Reporter.ReportEvent 0, "Links name: " & sName & "; URL: " & sHref Next
Click here for more QTP code snippets.
Above code will not work if you open multiple browsers. Check it if you want.
ReplyDeleteSubbu.
Yes, it may fail. But, as a best practice, we always have only one browser instance open. We should be aware of the fact that QTP gets confused when there are multiple instances of the application open (on multiple browsers). However, there are ways of handling it, but not advisable.
ReplyDeleteGood one.....
ReplyDeleteHi
ReplyDeleteOn running the above script, I am receiving a Syntax error for the below line:
Set nLinksCollection = Browser("title:=.*"”).Page("title:=.*").ChildObjects(oLinkDesc)
Could someone please take a look? I have a single browser open ( that is Firefox and all scripts run on IE.)
Hi there, it is not a good idea to try in FF. IE is the best supported browser by QTP.
Deleteu have to give the Exact browser class name and the page name , after that it wont gives the syntax error
DeleteHow to export link name and urls to an excel sheet rather than using Reporter.reportevent?
ReplyDelete