Give me some scripts for 1). checking webpage links
(counting links,opening web pages,counting child elements)
Answer Posted / rnashok
' Create object references to the Browser and Page objects.
Set BrowserObj =Browser("Yahoo!")
Set BrowserPageObj = Browser("Yahoo!").Page("Yahoo!")
' Set a description object to identify links.
Set oDesc = Description.Create()
oDesc("html tag").Value = "A"
' Get a collection of links
Set oLinkCollection = BrowserPageObj.ChildObjects(oDesc)
ItemCnt = oLinkCollection.Count-1
' Loop through the link collection
For i = 0 to ItemCnt
msg = ""
' Highlight and click link i.
Set oLink = oLinkCollection.Item(i)
oLink.Highlight
linkText = oLink.GetROProperty("innertext")
msg = "link text = " & linkText & vbNewLine
oLink.Click
BrowserObj.Sync
' Read page title.
titleStr = mid(BrowserPageObj.GetROProperty("title"),1,50)
msg = msg & "page title = " & titleStr & vbNewLine
' Check if page load had error.
If instr(1,titleStr,"Cannot find server") > 0 or
instr(1,titleStr,"HTTP 404") > 0 Then
msg = msg & "==> broken link" & vbNewLine
Reporter.ReportEvent micFail, "Link " & linkText, msg
else
msg = msg & "==> good link" & vbNewLine
Reporter.ReportEvent micPass, "Link " & linkText, msg
End If
' Navigate back to links page.
BrowserObj.Back
BrowserObj.Sync
' Rebuild link collection, navigating away and back
destroys previous collection.
Set oLinkCollection = BrowserPageObj.ChildObjects(oDesc)
Next
' Release the objects
Set oLinkCollection = nothing
Set BrowserObj = nothing
Set BrowserPageObj = nothing
Set oDesc = nothing
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Connect to QC using AOM.
I used child objects to get the no of weblist present in the weblist.now i need to select the items present in each weblist ?How to do so
What is the use of Debug Viewer?
Call to copy of an action and call to existing action… i know the diff but in real project how to use..? i want live scenario.pls help me..
how do i know how to use tools
How to handle the exceptions using recovery secnario manager in quicktest professional (qtp)?
How to test fly out menu in qtp?
How often were they executed?
write a script to verify the image path(src property) of the images which are in web pages.
Can any one explain me what is the procedure to connect the remote desk by using QTP 9.2 ?
How is test case write?
how to post xml data from QTP scripts to any application?
What are the different ways to invoke an application using QTP?
How are actions and functions different in QTP?
Explain the Different types of QTP test assets and their extensions?