分类:
2008-10-15 16:42:15
set a= Browser("Yahoo!")
set b= Browser("Yahoo!").Page("Yahoo!")
call CheckLinks(a,b)
Function CheckLinks (BrowserObject,BrowserPage)
CheckLinks=TRUE
Dim s_URL,i_CreationTime
Dim s_LinkOuterText,s_LinkInnerText,s_Linkhref
s_URL=BrowserPage.GetROProperty("url")
i_CreationTime=1
i_LinkCount=BrowserPage.object.links.length - 1
Dim i_Link
For i_Link=0 to i_LinkCount
If Trim(BrowserPage.object.links(i_Link).target)="" Then
BrowserPage.object.links(i_Link).target="_blank" ' Set the link to open i a new window so that we dont have any change in current window
End If
BrowserPage.object.links(i_Link).click
On error resume next
Browser("CreationTime:=" & i_CreationTime).sync
Browser("CreationTime:=" & i_CreationTime).Page("micClass:=Page").sync
On error goto 0
Dim s_LinkDetails
IHTML = Browser("CreationTime:=" & i_CreationTime).Page("micClass:=Page").object.Body.innerHTML
'Check if page was not able to be displayed
If (InStr(IHTML,"HTTP 404") <> 0) Or (InStr(IHTML,"cannot be displayed") <> 0) Then
s_LinkDetails="Link Broken" + vbcrlf + "Link Details:" +vbcrlf
s_LinkDetails=s_LinkDetails+"OuterText: "+ s_LinkOuterText + vbcrlf
s_LinkDetails=s_LinkDetails+"InnerText: "+ s_LinkInnerText + vbcrlf
s_LinkDetails=s_LinkDetails+ "href: " + s_Linkhref+ vbcrlf
s_LinkDetails=s_LinkDetails+ "Links Open in New Browse: " & bNewBrowser & vbcrlf
Reporter.ReportEvent micWarning,"Check Link(" & i_Link & ") -> " & s_LinkOuterText ,s_LinkDetails
CheckLinks=FALSE
Else
s_LinkDetails="Link Working" + vbcrlf + "Link Details:" +vbcrlf
s_LinkDetails=s_LinkDetails+"OuterText: "+ s_LinkOuterText + vbcrlf
s_LinkDetails=s_LinkDetails+"InnerText: "+ s_LinkInnerText+ vbcrlf
s_LinkDetails=s_LinkDetails+ "href: " + s_Linkhref+ vbcrlf
s_LinkDetails=s_LinkDetails+ "Links Open in New Browse: " & bNewBrowser & vbcrlf
Reporter.ReportEvent micPass,"Check Link(" & i_Link & ") -> " & s_LinkOuterText ,s_LinkDetails
End If
Browser("CreationTime:=1").close ' Close the link open.
Next
End Function