Micro Focus QTP (UFT) Forums
This code does not give total no of links present on page plz help it returns 0 - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: This code does not give total no of links present on page plz help it returns 0 (/Thread-This-code-does-not-give-total-no-of-links-present-on-page-plz-help-it-returns-0)



This code does not give total no of links present on page plz help it returns 0 - excellentpawan - 07-23-2013

This code does not give total no of links present on page plz help it returns 0

Code:
systemutil.Run "iexplore.exe","ansfoundation.org"

browser("IE8").Page("Page for Archive link").Image("Image").Click
Set obabstract = description.Create
obabstract("name").value = "[Abstracts]"
obabstract("micclass").value = "Link"
browser("IE8").Page("Page for Archive link").Sync
set issuecount = browser("title:=.*").Page("title:=.*").ChildObjects(obabstract)
print issuecount.count



RE: This code does not give total no of links present on page plz help it returns 0 - Ankur - 07-23-2013

I saw a similar question being asked by you around last week. While it is fine to ask questions when in doubt, it won't help you at all if for every little problem you ask others.
Try to debug it yourself, tell us what you did, for sure you will get more and better answers.

No hard feelings. Just a bit of advise.


RE: This code does not give total no of links present on page plz help it returns 0 - vinod123 - 07-24-2013


Code:
systemutil.Run "iexplore.exe","ansfoundation.org"
Browser("micclass:=Browser").Page("micclass:=Page").Image("Image").Click
Set obabstract = Description.Create
obabstract("name").value = "[Abstracts]"
obabstract("micclass").value = "Link"
Browser("micclass:=Browser").Page("Page for Archive link").Sync
set issuecount = Browser("title:=.*").Page("title:=.*").ChildObjects(obabstract)
print issuecount.count



RE: This code does not give total no of links present on page plz help it returns 0 - excellentpawan - 07-24-2013

Here is webtable on the page and links are in webtable so i am unable to count as i am beginner I thought forum can help me in learning qtp.


RE: This code does not give total no of links present on page plz help it returns 0 - learnQtptips - 07-24-2013

This might help you while debugging.
Just check the browser that is active and the browser, you are trying to retrieve the link.

Code:
[b]Browser("micclass:=Browser").Page("Page for Archive link")[/b].Sync
set issuecount = [b]Browser("title:=.*").Page("title:=.*")[/b].ChildObjects(obabstract)

Second,
as you said ur links are within the webtable, you should apply the description object on the webtable not on the page like....

Code:
set issuecount = [b]Browser("title:=.*").Page("title:=.*").webtable("xxxx")[/b].ChildObjects(obabstract)



RE: This code does not give total no of links present on page plz help it returns 0 - chandra402 - 07-25-2013

As you said its in Table, first you frezee the 'Coloumn No:' & then write 'for loop' finding in each row.
above is best suited for row count < 20 to 30.


RE: This code does not give total no of links present on page plz help it returns 0 - excellentpawan - 07-25-2013

returns 0


RE: This code does not give total no of links present on page plz help it returns 0 - Ankur - 07-25-2013

As I said earlier, we don't have any issues with someone asking questions all I am suggesting to you is, if you're asking similar queries, try to debug yourself first and LET US KNOW WHAT YOU TRIED to get faster and better responses.

Anyways, answering your question, this piece of code will work for any page

Code:
systemutil.Run "iexplore.exe","ansfoundation.org"

Set oLinks = Description.Create()
oLinks("micclass").Value = "Link" 'Collection of Link Objects

Set PageLinks = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oLinks)
msgbox PageLinks.count 'Total count

For i = 0 To PageLinks.count - 1     
msgbox PageLinks(i).GetRoProperty("href") 'Name the links
Next



RE: This code does not give total no of links present on page plz help it returns 0 - yogi4tech - 01-17-2015

Hi pawan, even though your post is old from 2013 i just joined and wanted to give you a solution to your problem. Or people like you to troubleshoot if your code returns 0 as a value of link present on a web page
You could do it few different ways the simplest way to do this is, to use Regular Expression which can count link present on any browser which is open and count the links.
Please note that you may have multiple browsers running on your computer or local machine such as chrome, firefox and IE at the same time. Therefore if you want to count links present on google.com which is opened on internet explorer. Do these steps.
1. go to the task bar and right click on internet explorer
2.again select the internet explorer highlighted icon and right click .
3. you will see a dialogue box open and you will see an option "RUN AS AN ADMINISTRATOR"
4. Click on run as an administrator.
if you don't run the browser as an administrator the QTP doesn't invoke the browser and the webpage available within that browser, so even though the syntax of the script is ok it returns the value as "0"
here I am giving you the script which not only will return the number of links present but also it will print on datasheet and it will export the datasheet to an excel file in your C drive. try this and hope this Helps.
And don't listen to people like ANkur who they put newbies down by insulting them. They actually forget that they were new to this field sometimes back.
Peace and here is the code.

Code:
Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"

'Here is the regex for any webpage which is open on a browser
Set Links = browser("creationtime:=0").page("title:=.*").ChildObjects(oDesc)
print  "Total links present: " & Links.Count
' here is to print the link names to datasheet in qtp
datatable.GlobalSheet.AddParameter"linkNames",""
'obj.Count value has the number of links in the page
For i = 0 to Links.Count - 1    
    datatable.SetCurrentRow(i+1)
'  get the name of all the links in the page            
datatable("linkNames")  = Links(i).GetROProperty("name")
datatable.Export"c:\Nanu1_Links.xls"
  
Next