Micro Focus QTP (UFT) Forums
Check all links of a website - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Check all links of a website (/Thread-Check-all-links-of-a-website)



Check all links of a website - sia sharma - 06-21-2012

Hi all,

i want to check whether all links of my web site are working fine using qtp
i have used standard checkpoint and selected an option check broken links
the code generated -

link check for google site
Code:
Browser("Google").Page("Google").Check CheckPoint("Google")
it is giving a fail result Sad

is there any other way in qtp to find out the broken links
thanks
sia


RE: Check all links of a website - ssvali - 06-21-2012

Try the below code
Code:
Set alllinkob = Description.Create()
alllinkob("micclass").value ="Link"

Set objAlllinkObj = Browser("Google").Page("Google").ChildObjects(alllinkob)

For a =0 to objAlllinkObj.count-1

url = objAlllinkObj(a).getroproperty("url")

call geturlstatus(url )

Next

Public Function geturlstatus(url )
    On Error Resume Next
    Call ClearBrowserCache()
    Set webService = nothing
    Set webService= CreateObject("Microsoft.XMLHTTP")  ' Create an xmlhttp object
    webService.open "GET", url, False     ' Opens the connection to the remote server
    webService.Send
    pagestatus = webService.status
    If pagestatus < 200 or pagestatus >399 Then
        print "In valid request" & pagestatus &"" & url
        geturlstatus = 0
    else
        geturlstatus = 1
        print "valid request"& pagestatus &"" & url
    End If
    Set webService = nothing
    err.clear
End Function