More

    UFT Function to click link inside a WebTable

    In this post, we will discuss how to click a link inside a web table based on value present in the same or another column in the same row using UFT.

    Introduction

    While we do automation testing using UFT on web applications, we face scenarios where we must click a link inside a web table that holds a lot of items.

    In certain scenarios, these links could be dynamic based on several factors like filters applied, permissions, the region of access, etc. Such scenarios make it difficult to click a specific link.

    We have a function that works with UFT which can click a link based on link text or based on the text in another column of a web table.

    As an example, let us consider the following web table with some student data.

    Sample Web Table

    Sl. NoStudent NameAddressProgress Report
    1RahulAddressProgress Report
    2SameerAddressProgress Report
    3AustinAddressProgress Report
    4LibinAddressProgress Report
    5MaheshAddressProgress Report
    6VineethAddressProgress Report
    7HareeshAddressProgress Report
    8PraveenAddressProgress Report
    9ArunAddressProgress Report
    10AnuAddressProgress Report

    Scenario

    As you can see, each student listed in the table has a link to their address and progress report. They all have the same properties and we cannot distinguish them with the links alone.

    In this scenario, we are asked to click the link against the student Mahesh? We can do it with the below function.

    The Function

    Function Overview
    Function NameSearchTextAndClickLink(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal LinkColumn)
    Function DescriptionFunction to click a link in a web table based on value present in same or another column in the same row.
    Data Parameters
    TestObjectSpecify the WebTable. eg: Browser("-----").Page("-----").WebTable("-----")
    SearchTextSpecify the text to search in the WebTable. eg: “Cruises”
    SearchTextInColumnSpecify the column in which text is to be searched as long. eg: 2
    LinkColumSpecify the column where the link resides in the WebTable as long. eg: 3
    '------------------------------------------------------------------------------------------------------------------------------------
    'Function Name                    : SearchTextAndClickLink(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal LinkColumn)
    'Function Description             : Function to click a link in a web table based on value present in same or another column in the same row.
    'Data Parameters                  : TestObject:- Specify the WebTable. eg: Browser("-----").Page("-----").WebTable("-----")
    '                                   SearchText:- Specify the text to search in the WebTable. eg: "Cruises"
    '                                   SearchTextInColumn:- Specify the column in which text is to be searched as long. eg: 2
    '                                   LinkColum:- Specify the column where the link resides in the WebTable as long. eg: 3
    '------------------------------------------------------------------------------------------------------------------------------------
    Function SearchTextAndClickLink(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal LinkColumn)
     'in case of any errors
       On Error Resume Next
       'checking whether the object exist
       ObjectExist = TestObject.Exist(10)
       If ObjectExist Then
        'setting MatchFound as false
        MatchFound = FALSE
        'finding the total number of rows in the webtable
        TotalRows = TestObject.RowCount
        'looping in the webtable until a match is found
        For CRow = 1 to TotalRows
         'checking whether Searched Text is found
         If SearchText = Trim(TestObject.GetCellData(CRow, SearchTextInColumn)) Then
          'saving the row where the value is found to a variable
          FoundRow = CRow
          'setting MatchFound as true
          MatchFound = TRUE
          Exit For
         End If
        Next
        'in case a match is found
        If MatchFound Then
         'setting the object link
       Set LinkObject = TestObject.ChildItem(FoundRow, LinkColumn, "Link", 0)
       'clicking the link
       LinkObject.Click
       'reporting successfull link click
       Reporter.ReportEvent micPass, "Specified Link Clicked Successfully.", "Successfully clicked the link " & LinkObject.GetROProperty("Text") & "."
       'in case match is not found
           ElseIf Not MatchFound Then
        'reporting error if specified text is not found in the webtable
       Reporter.ReportEvent micFail, "Cannot Find Specified Text", "Cannot find the text " & SearchText & " in the object specified in function call."
        End If    
       ElseIf Not ObjectExist Then
       'reporting error if the specified object is not found
      Reporter.ReportEvent micFail, "Cannot Find The Object", "Object specified in function call cannot be found."
       End If
    End Function

    Function Usage

    The code below, when used in UFT, will call the function so that it clicks the address link against the student Mahesh.

    Set HomeTable = Browser("Browser").Page("Page").WebTable("Sl. No")
    Call SearchTextAndClickLink(HomeTable, "Mahesh", 2, 3)

    We have another article which details how to check the presence of an item in a web table. Read more by clicking here.

    Related Articles

    Recent Articles

    How to fix Date Time data type issue in Blue Prism?

    Know more about the date time issue while using the code stage in Blue Prism and understand how to fix it by dealing with the UTC offset.

    How to deserialize JSON in UiPath?

    Tutorial on how to properly deserialize JSON with UiPath Web Activities. Explains the concept of JSON Array and JSON Object.

    Dynamic or Variable Selectors in UiPath

    Tutorial on how to use dynamic selectors in UiPath. Explains how to use variables in UiPath selectors.

    Change Case Excel Add-In

    Change Case Excel Add-In is a powerful Excel Add-In that can change the case of selected cells. With easy to use Keyboard shortcuts, perform case conversion in style.

    Blue Prism Video Tutorial

    A well-structured video tutorial on Blue Prism, which is the right starting point for your RPA career. #rpa #blueprism

    1 Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Stay on top - Get latest articles in your inbox