How to retrieve all the link names and URLs using QTP?
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 manner:
1) Using the ChildObjects method, get all the links on the webpage.
2) Now we have the collection object ready.
3) Using GetROProperty method to retrieve the required property values.
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
No comments:
Post a Comment