Johnny
Johnny

Reputation: 61

How do I click on a Link that is available in a Web table?

Spy screenshot

I am trying to click on the link however I am not able to do it due to the WebTable.

So I have created my function library and this is code for the link and I am trying to Call it. I used name fyi.

Call ClickLink ("sign-in") 



Sub ClickLink(LinkName)

 Set myPage=Browser("title:=.*").Page("title:=.*").Webtable()
 Set wLink = description.Create()  
    wLink("micClass").value="Link"  

    Set allLinks = myPage.ChildObjects(wLink) 
    TotalLinks = allLinks.count() 

    For Iterator = 0 To TotalLinks -1 
        If allLinks(i).GetRoproperty("name") = LinkName Then
            allLinks(i).click
            wait(3) 
            Exit For   

    ElseIf TotalLinks -1 Then 
        reporter.ReportEvent micFail, "Find Link", LinkName 
    End If  
    Next

    Set myPage = Nothing    
    Set wLink = Nothing 
    Set allLinks = Nothing


 End Sub

Upvotes: 1

Views: 1648

Answers (2)

mbn217
mbn217

Reputation: 914

You can use this function that i created a while back , Its very dynamic , so it accepts any values that are present

Function DARRTS_Click_Webelement_From_Webtable(clasVal,htmlidVal,Elementinnertext_To_Click,index)
On error resume next
Dim oDesc
'create description of the object
Set oDesc = Description.Create
oDesc.Add "MicClass","WebTable"
oDesc.Add "class",clasVal
oDesc.Add "html id",htmlidVal

If index <> "" Then
    oDesc.Add "index", index
End If

Element_innertxtVal = Elementinnertext_To_Click

i_RowCount = PageObj.Webtable(oDesc).RowCount

For rowNum = 1 to i_RowCount

    For ColNum = 1 to PageObj.Webtable(oDesc).ColumnCount(i_RowCount)

    set o_ElementObject = PageObj.Webtable(oDesc).childitem(rowNum,ColNum, "WebElement",0)

     s_ObjectName = o_ElementObject.GetROProperty("innertext")

    if s_ObjectName = s_ElementClassName then

    o_ElementObject.click

    'your passing report

    Else

    ' your failing report

    end if

    Next

Next
On error goto 0

'clean up
Set oDesc = nothing
Set o_ElementObject = nothing

End Function

Where:

classVal- the class value of the webtable object

index - index num if there are multiple Links with same Text.Pass Blank "" in case there is no need for the index

htmlidVal- the class value of the webtable object

Elementinnertext_To_Click- the innertext of the webelement you want to click from the webtable object

Upvotes: 1

Motti
Motti

Reputation: 114695

The WebTable should not interfere with identifying the link in any way, what causes you to think that it does? In UFT you can omit intermediate levels in the DOM hierarchy.

From the screenshot it appears that the Link object is already in the object repository, try clicking it the simple way.

 Browser("Register: Mercury Tours").Page("Register: Mercury Tours").Link("sign-in").Click

Further reading: Understanding the Web Test Object Model in HP Unified Functional Testing (UFT).

Upvotes: 2

Related Questions