How to check all the links dynamically?

Hi Expert,

The following thing I have to do using VBScript in QTP 10/11:

The VBScript opens one login page. After the login it counts the number of links in that page and then prints all the links. Afterwards it opens every link one by one.

I am having issues with finding all the dynamic links.

Last updated:6/20/2013 5:40:25 AM

1 Answers

Sumit Kesarwani
Sumit Kesarwani


You can get all the links on a page by using the Page's (or Frame's) ChildObject method.

Set desc = Description.Create()
desc('html tag').Value = 'a'
Set links = Browser('B').Page('P').ChildObjects(desc)
For i = 0 to links.Count - 1
    Print links(i).GetRoProperty('inner_text') & ' => ' & links(i).GetRoProperty('href')
As for clicking them, that's a bit more complicated since after clicking a link you cause a navigation that invalidates the links object, you should either perform 

the ChildObjects each time (while keeping track of the index) or open the links in a different browser/tab.