How to return the total number of links in a webpage and their names and URLs
How to return the total number of links in a webpage and their names and URLs
Solution: Use ChildObjects to get the link collection, then retrieve the properties
Use the ChildObjects method to retrieve all the links on the specified webpage. Once you have the collection, you can use the GetROProperty method to retrieve the innertext (name) and href (URL) values.
object.ChildObjects (pDescription)
object |
A Page or Frame object. |
pDescription |
The description of the object to retrieve. |
Use the Description object to store the description of the object type to retrieve.
Example:
‘ The sample was created against http://www.google.com
Set oDesc = Description.Create()
‘ Retrieve HTML tag <A>
oDesc(“html tag”).Value = “A”Set rc = Browser(“Google”).Page(“Google”).ChildObjects(oDesc)
num = rc.Count()
tag = rc(i).GetROProperty(“innertext”)
href = rc(i).GetROProperty(“href”)
Reporter.ReportEvent 0, “Links in Page”, “name: ” & tag & “; url: ” & href
Next
Source: Mercury Forum’s KB articles
3 Comments »
Leave a comment
-
Archives
- July 2011 (1)
- March 2011 (1)
- November 2010 (1)
- November 2008 (4)
- October 2008 (2)
- September 2008 (2)
- June 2008 (1)
- March 2008 (4)
- February 2008 (44)
-
Categories
- Automated Test Script Creation Process
- Automating MS Word
- Automating QC
- Automation Object Model For QTP
- Backward compatability in QTP
- Browser Scripts
- COM and QTP
- compare 2 text files
- Descriptive programming
- Descriptive Programming and Child Objetcs
- Dictonary Object
- DotNetFactory
- Excel Automation
- Extra Topics
- Files and Folders
- General Standards to be followed in Test scripts
- New Features In QTP9.5
- QC-OTA
- QTP Additional Faqs
- QTP Faqs
- QTP Naming Convention
- QTP Tips and Faqs
- Running stored procedures from QTP
- Send keyboard keys
- Uncategorized
- Uninstall a software using QTP
- Uninstall a software using vbscript
- Update data in a database
- VBScript and IE Automation
- VBScript Faqs and Useful resources
- What’s New in Quick Test Pro 9.0
- Whats New in QTP 9.5
- XML Scripting
-
RSS
Entries RSS
Comments RSS
How do you do this for any URL that is being passed by the user
For the above code you need the objects in the OR. How would you do it if the objects are not in the OR?
Comment by Yesh | December 4, 2008 |
Thanks,Mohan,
It works pretty good.
Comment by Dev | November 27, 2009 |
After running once, it throws general run error.
can you please help me out on the issue
Comment by Madhu | November 15, 2011 |