QTP tutorials & interview questions


Search more on QTP here

QTP Script 16 - How to count total number of links on a web page?

Counting Total Links on a web page

Make sure www.google.com is open and write the below code in a new test and run it. It may show different results than mine, depending on the links on Google page at that time. I have shown my answer below.

Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col = Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
msgbox link_col.count

'You must use the Description object to create the programmatic description for the ChildObjects description argument. You cannot enter the programmatic description directly into the argument using the property:=value syntax.