Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Thursday, May 28, 2009

Working with links Using DOM


Click Here to read a brief description about Document Object Model

'********************************************************************************

'********************************************************************************
'Print All Link Names From a Page

Function fnGetAllLinkNames(oParentObject)

    Dim lnkObjects
    Dim lnk   
   
    set lnkObjects=oParentObject.Object.getElementsByTagName("a")    ' A is the tag name to create  Links in HTML
    print "Total Number of links in the Page :- "&lnkObjects.length
   
    For each lnk in lnkObjects
        print lnk.outerText
    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function

'Calling the Function with a parent object
Set oParentObject=Browser("Google").Page("Google")
fnGetAllLinkNames(oParentObject)

'********************************************************************************

'********************************************************************************

'Click on a specified Link

Function fnClickLink(
oParentObject,LnkName)

    Dim lnkObjects
    Dim lnk

    set lnkObjects=oParentObject.Object.getElementsByTagName("a")
       
    For each lnk in lnkObjects

        If lcase(lnk.outerText)=lcase(LnkName) then
            lnk.click
            Exit for
        End If

    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function

'Calling the Function with Parent and with link name Images
Set oParentObject=Browser("Google").Page("Google")
fnClickLink oParentObject,"Images"

'********************************************************************************

'********************************************************************************

No comments :

Post a Comment