Quick test professional

QTP Tips QTP codes QTP Faqs and more

How to return the total number of links in a webpage and their names and URLs

How to return the total number of links in a webpage and their names and URLs

Solution: Use ChildObjects to get the link collection, then retrieve the properties

Use the ChildObjects method to retrieve all the links on the specified webpage. Once you have the collection, you can use the GetROProperty method to retrieve the innertext (name) and href (URL) values.

object.ChildObjects (pDescription)


A Page or Frame object.


The description of the object to retrieve.

Use the Description object to store the description of the object type to retrieve.

‘ The sample was created against http://www.google.com
Set oDesc = Description.Create()
‘ Retrieve HTML tag <A>
oDesc(“html tag”).Value = “A”
Set rc = Browser(“Google”).Page(“Google”).ChildObjects(oDesc)
num = rc.Count()

For i=0 to num-1
   tag = rc(i).GetROProperty(“innertext”)
   href = rc(i).GetROProperty(“href”)
   Reporter.ReportEvent 0, “Links in Page”, “name: ” & tag & “;    url: ” & href

    Source: Mercury Forum’s KB articles



February 14, 2008 - Posted by | Descriptive Programming and Child Objetcs | , , , , , , , ,


  1. How do you do this for any URL that is being passed by the user

    For the above code you need the objects in the OR. How would you do it if the objects are not in the OR?

    Comment by Yesh | December 4, 2008 | Reply

  2. Thanks,Mohan,

    It works pretty good.

    Comment by Dev | November 27, 2009 | Reply

  3. After running once, it throws general run error.
    can you please help me out on the issue

    Comment by Madhu | November 15, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: