Interview Questions   Tutorials   Discussions   Programs   Videos   

QTP - Write a QTP script to print all the link names displayed in a web page

asked marvit August 20, 2014 04:12 AM  

Write a QTP script to print all the link names displayed in a web page


1 Answers

answered By Dharma   0  
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 :

' 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


   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!