Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check broken link in a page
#1
Not Solved
I created a script that will check broken link in a page means valid url is that or not but i am not getting a url which one is call by javascript. Error is show in attachment


'Find out all the links in the page using ChildObjects
Code:
Set oLink = Description.Create
oLink("micclass").Value = "Link"
Set oAllLinks = Browser("title:=.*").Page("title:=.*").ChildObjects(oLink)

'Find out the count of links
Code:
iTotalLinks = oAllLinks.Count
msgbox iTotalLinks

'Loop through all the links to find if the link is broken or not
Code:
For i=0 to iTotalLinks - 1
  a =  oAllLinks(i).GetROProperty("name")
' print a
  'Find out the url for the link
  sURL = oAllLinks(i).GetROProperty("url")
  sText = oAllLinks(i).GetROProperty("text")
'  print sText  & " : " & sURL
'  aURL = oAllLinks(x).GetROProperty("a href")
'If sURL = url and  href Then
    Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
     print sText  & " : " & sURL

  objWinHTTP.Open "GET", sURL,False

  objWinHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

'Send the Request to the Server and capture the response
Code:
objWinHTTP.Send
  iReturnVal = objWinHTTP.Status

  'Find out if the Link exists or is broken
  If iReturnVal = 200 Then
    'msgbox "Link - " & sURL & " Exists"
    Reporter.Reportevent micPass, "links","links exist :"&sURL
    'print sURL
ElseIf iReturnVal = 404 Then
    'msgbox "Link - " & sURL & " is Broken"
    Reporter.ReportEvent micFail, "links","404 Error:"&sURL
    'print sURL
  Else
    msgbox "Code" - iReturnVal


End If
    
'  End If

  Set objWinHTTP = Nothing

Next


Attached Files
.doc   Problem in QTP.doc (Size: 493.5 KB / Downloads: 91)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to create web objects (like Browser, Link, Page, etc) Arena 2 3,649 04-03-2012, 08:21 AM
Last Post: Arena
  Fixing broken Checkpoints mv8167 2 2,717 02-02-2012, 10:00 PM
Last Post: mv8167
  How to check all values on a page. upadhyay40 0 1,794 12-09-2009, 03:49 PM
Last Post: upadhyay40
  How to check validations for all field in a page upadhyay40 3 2,993 12-03-2009, 03:52 PM
Last Post: phanindranath
Question How to check for a static text in a web page using desrciptive programming? jaykisan 4 5,422 12-03-2009, 10:13 AM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)