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
#9
Solved: 10 Years, 9 Months, 1 Week 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


Messages In This Thread
RE: This code does not give total no of links present on page plz help it returns 0 - by yogi4tech - 01-17-2015, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to check expected cookies are present or not priyanka.agarwal 0 1,873 07-02-2015, 12:43 PM
Last Post: priyanka.agarwal
  VB Script to count number of links in a web page. Suma Parimal 4 24,766 07-01-2015, 12:59 PM
Last Post: govind
  how to get a link present under mouseover action priyadarisini 1 2,169 12-03-2013, 08:59 PM
Last Post: Parke
  I want to compare string present on two pages excellentpawan 3 3,308 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 6,766 07-23-2013, 11:51 AM
Last Post: Ankur

Forum Jump:


Users browsing this thread: 1 Guest(s)