Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This code does not give total no of links present on page plz help it returns 0
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
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.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago

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
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
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.
Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
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)
Reply
#6
Solved: 11 Years, 3 Months, 4 Weeks ago
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.
Reply
#7
Solved: 11 Years, 3 Months, 4 Weeks ago
returns 0
Reply
#8
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#9
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to check expected cookies are present or not priyanka.agarwal 0 1,966 07-02-2015, 12:43 PM
Last Post: priyanka.agarwal
  VB Script to count number of links in a web page. Suma Parimal 4 25,257 07-01-2015, 12:59 PM
Last Post: govind
  how to get a link present under mouseover action priyadarisini 1 2,306 12-03-2013, 08:59 PM
Last Post: Parke
  I want to compare string present on two pages excellentpawan 3 3,467 07-23-2013, 02:33 PM
Last Post: ssvali
  I want to count total no of links in a page and click one by one excellentpawan 9 7,233 07-23-2013, 11:51 AM
Last Post: Ankur

Forum Jump:


Users browsing this thread: 1 Guest(s)