How to get count of all links on a web page and click on each link using Description Object (Description.Create) in QTP

'Open the URL
Systemutil.Run "iexplore","www.gooogle.com"

'Create the Browser object  -  No need to create for this example as we are using 'creationtime' to recognise the browser
Set oBrowser = Description.Create
oBrowser("micclass").value = "Browser"
oBrowser("name").value = "Google"

'Create the Page object
Set oPage = Description.Create
oPage("micclass").value = "Page"
oPage("title").value = "Google"

'Create the Link object
Set oLink = Description.Create
oLink("micclass").value = "Link"
oLink("html tag").value =  "A"

'Get all links (child items with link as type) for the browser
Set colObject = Browser("Creationtime:=0").Page(oPage).ChildObjects(oLink)

'Display count of all links
Msgbox ColObject.Count

'Open each link and capture its name and URL values
'For i=0 to ColObject.Count - 1
For i=2 to ColObject.Count -1
    URL =  colObject(i).GetROProperty("url")
    Namee = colObject(i).GetROProperty("Name")
    Browser("Creationtime:=0").Object.Navigate URL, Clng(&H800) 'The 'Clng(&H800)' parameter will open the URL in new tab
If Browser( "creationtime:=1").Exist (30) Then 
    Browser( "creationtime:=1").Sync
    Wait 2
    Browser( "creationtime:=1").Close
    Reporter.ReportEvent micPass, "The link:- " &Namee &" is opened sucessfully with URL: " &URL, ""
Else
    Reporter.ReportEvent micFail, "The link:- " &Namee &" is not opened sucessfully with URL: " &URL, ""
End If

Next

Comments

Popular Posts

Mastering Selenium Exceptions for Robust Test Automation

Mastering Salesforce Testing: A Technical Deep Dive

The Singleton Pattern in Test Automation: Ensuring Consistency and Efficient Resource Management

Future of .NET BDD: An Introduction to ReqnRoll

Mastering Java Collections: Your Secret Weapon for Robust Automation Frameworks