More

    UFT Function to check the presence of an item in a WebTable

    In this post, we will discuss how to check the presence of an item in a web table using Micro Focus UFT (formerly Quick Test Professional or QTP).

    We will validate the presence or absence of an item in a web table using a function. The condition specified in the function call is validated to generate results.

    Sample Web Table

    Sl. NoStudent NameStatus
    1RahulPassed
    2SameerPassed
    3AustinPassed
    4LibinPassed
    5MaheshPassed
    6VineethPassed
    7HareeshPassed
    8PraveenPassed
    9ArunPassed
    10AnuPassed

    So let’s take an example of a web table which holds the name of students who have passed in an exam. Let’s say Mahesh passed the exam and unfortunately Basheer failed in it. Now we have to test whether the web table contains Mahesh and that it does not hold Basheer.

    Function Overview
    Function NameSearchTextAndClickLink(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal LinkColumn)
    Function DescriptionFunction to validate the presence of an item in a WebTable
    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
    ExpectedResultSpecify TRUE or FALSE, TRUE if the item should exist in the webtable and FALSE if it should not.

    The Function

    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    'Function Name                    : SearchItemInWebTable(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal ExpectedResult)
    'Function Description             : Function to validate the presence of an item in a webtable
    '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
    '                                   ExpectedResult:- Specify TRUE or FALSE, TRUE if the item should exist in the webtable and FALSE if it should not
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Function SearchItemInWebTable(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal ExpectedResult)
       '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
          'setting MatchFound as true
          MatchFound = TRUE
          Exit For
         End If
        Next
        If ExpectedResult Then   
         'in case a match is found
         If MatchFound Then
          'reporting pass if specified item is found in the webtable
        Reporter.ReportEvent micPass, "Specified Item Found", "Specified item " & SearchText & " is present in the web table."
        'setting function value
        SearchItemInWebTable = TRUE
        'in case match is not found
         ElseIf Not MatchFound Then
        'reporting error if specified item is not found in the webtable
        Reporter.ReportEvent micFail, "Cannot Find Specified Item", "Cannot find the specified item " & SearchText & " in the web table."
        'setting function value
        SearchItemInWebTable = FALSE
         End If
        ElseIf Not ExpectedResult Then
         'in case a match is found
         If MatchFound Then
          'reporting error if specified item is found in the webtable
        Reporter.ReportEvent micFail, "Specified Item Found", "Specified item " & SearchText & " is present in the web table contrary to what was expected."
        'setting function value
        SearchItemInWebTable = FALSE
        'in case match is not found
         ElseIf Not MatchFound Then
        'reporting error if specified item is not found in the webtable
        Reporter.ReportEvent micPass, "Cannot Find Specified Item", "Cannot find the specified item " & SearchText & " in the web table as expected."
        'setting function value
        SearchItemInWebTable = TRUE
         End If             
        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

    'setting the web table as the test object for the function
    Set MyWebTable = Browser("QTP Function to Click").Page("QTP Function to Click").WebTable("Sl. No")
    'calling the function to check whether student Mahesh is present in the web table
    Call SearchItemInWebTable(MyWebTable, "Mahesh", 2, TRUE)
    'calling the function to validate the absence of student Basheer in the web table
    Call SearchItemInWebTable(MyWebTable, "Basheer", 2, FALSE)
    'calling the function to check whether student Basheer is present in the web table
    Call SearchItemInWebTable(MyWebTable, "Basheer", 2, TRUE)
    'calling the function to validate the absence of student Mahesh in the web table
    Call SearchItemInWebTable(MyWebTable, "Mahesh", 2, FALSE)
    'alternate usage of the function. Function returns TRUE or FALSE for the condition
    FoundPassedStudent = SearchItemInWebTable(MyWebTable, "Mahesh", 2, TRUE)
    'custom error reporting
    If FoundPassedStudent Then
     Reporter.ReportEvent micPass, "Found Passed Student", "Student Mahesh was found in the table of passed students."
    End If

    Possible use of function

    • After adding a new employee to your HRMS, you can check whether he is listed in search results. 
    • After deleting an employee you can check whether they come up in the search result.

    We have another article which details on how to click a link inside 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