GeekInterview.com
Series: Subject:
Question: 34 of 737

Count Number of Links

How to count number of links in a web page using QTP?
Asked by: shruthi.b | Member Since Aug-2010 | Asked on: Sep 9th, 2010

View all questions by shruthi.b

Editorial / Best Answer

Answered by: calvin_29

View all answers by calvin_29

Member Since Sep-2010 | Answered On : 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 - 4 of 4 Answers
calvin_29

Answered On : Sep 20th, 2010

View all answers by calvin_29

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


Yes  1 User has rated as useful.
  
Login to rate this answer.

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

  
Login to rate this answer.
ramprasad6

Answered On : Feb 1st, 2011

View all answers by ramprasad6

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

  
Login to rate this answer.

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") '

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.