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
'Find out the count of links
'Loop through all the links to find if the link is broken or not
'Send the Request to the Server and capture the response
'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