Count Number of Links

How to count number of links in a web page using QTP?

Questions by shruthi.b

Editorial / Best Answer

calvin_29  

  • Member Since Sep-2010 | Sep 20th, 2010


This is the script, We should first create an object

set oDesc=description.create()
'prefer descriptive programming...batter
oDesec("micclass").value="link"
'get all child objects in an variable
set oLink=browser("name:=.*").page("title:=.*").childobjects(oDesc)
'count all links
intC=oLink.count
'Use print or msgbox or 'reporter.reportevent'
print intC
'it glows links in the web page
for i=0 to intC-1
oLink(i).highlight
next
set oLink=nothing
set oDesc= nothing

'Offer me comment if it works properly

Showing Answers 1 - 18 of 18 Answers

calvin_29

  • Sep 20th, 2010
 

This is the script, We should first create an object

set oDesc=description.create()
'prefer descriptive programming...batter
oDesec("micclass").value="link"
'get all child objects in an variable
set oLink=browser("name:=.*").page("title:=.*").childobjects(oDesc)
'count all links
intC=oLink.count
'Use print or msgbox or 'reporter.reportevent'
print intC
'it glows links in the web page
for i=0 to intC-1
oLink(i).highlight
next
set oLink=nothing
set oDesc= nothing


'Offer me comment if it works properly


Dim mylink, linkcount

linkcount =0

Set MyObjLink = Description.Create()
MyObjLink("micclass").value = "Link"
MyObjLink("html tag").value = "A"

SystemUtil.Run "C:Program FilesInternet ExplorerIEXPLORE.EXE","","C:Documents and Settingsdfhdfhdfhdfh","open"
Set myObj = Browser("Google").Page("Google").ChildObjects(MyObjLink)

For i=0 to MyObj.count-1

mylink=MyObj(i).GetROProperty("url")
If mylink <>"" Then
 linkcount =linkcount+1
End If

Next

msgbox "Number of link on this page is " & linkcount

  Was this answer useful?  Yes

ramprasad6

  • Feb 1st, 2011
 

For counting the number of links in webbased

set obj=description.create()
obj("micclass").value="Link"


set Links=browser().page().childobject(obj)
NumofLinks=Links.count-1
for i=0 to Links(count)-1
       Links(i).select i+1
Next
      

  Was this answer useful?  Yes

By using Description object, which contains a 'mask' for objects we would like to get we can count number of links.

Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set Links = Browser("Google").Page("Google").ChildObjects(oDesc)
Msgbox "Total links present: " & Links.Count

Here 'ChildObjects' returns the collection of child objects matched the description ("micclass" is "Link") and contained within the object ' Page("Google") '

yogi

  • Dec 26th, 2014
 

your code doesnt work on set links line it throws an error as not supported method

  Was this answer useful?  Yes

rohan

  • May 22nd, 2015
 

By using descriptive programming we can count and displays the number of links in web page
Set ObjDesc = Description.Create
ObjDesc.Add "micclass","Link"
Set ObjBr = Browser("name:=*).Page("title:=*).ChildObjects(ObjDesc)
LCount = ObjBr.count
Print Lcount - displays the number of links
for i=0 to Lcount-1
Lname = ObjBr(i).getroproperty("name")
Print Lname - displays the link names
Next

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions