$show=home$hide=mobile-page

UFT Function to Check the presence of an item in a Web Table

UFT/QTP function to validate the presence or absence of an item in a WebTable. Condition specified in the function call is validated to report result.

UFT/QTP function to validate the presence or absence of an item in a WebTable. Condition specified in the function call is validated to report result
UFT/QTP function to validate the presence or absence of an item in a WebTable. Condition specified in the function call is validated to generate result.

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.
Sl. No Student Name Status
1 Rahul Passed
2 Sameer Passed
3 Austin Passed
4 Libin Passed
5 Mahesh Passed
6 Vineeth Passed
7 Hareesh Passed
8 Praveen Passed
9 Arun Passed
10 Anu Passed
Function Overview
Function Name SearchTextAndClickLink(ByVal TestObject, ByVal SearchText, ByVal SearchTextInColumn, ByVal LinkColumn)
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.

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.

COMMENTS





Name

AngularJS,3,Automation Testing,8,CSharp,5,Disqus,1,Excel,2,HP ALM,5,HTML5,1,ISTQB,2,Java Script,2,Manual Testing,7,Photography,1,Quiz,2,REST API,5,Testing,15,UFT,8,VB,5,VBScript,1,Wordpress,1,
ltr
item
Aneejian: UFT Function to Check the presence of an item in a Web Table
UFT Function to Check the presence of an item in a Web Table
UFT/QTP function to validate the presence or absence of an item in a WebTable. Condition specified in the function call is validated to report result.
https://3.bp.blogspot.com/-L38kwFWGEqM/WMoDA8vz--I/AAAAAAAAAHc/F6EEI98hWC48gH6rORugE1QjVetAaKERgCLcB/s320/webtableitempresence.jpg
https://3.bp.blogspot.com/-L38kwFWGEqM/WMoDA8vz--I/AAAAAAAAAHc/F6EEI98hWC48gH6rORugE1QjVetAaKERgCLcB/s72-c/webtableitempresence.jpg
Aneejian
http://www.aneejian.com/2012/11/uft-function-check-presence-item-web-table.html
http://www.aneejian.com/
http://www.aneejian.com/
http://www.aneejian.com/2012/11/uft-function-check-presence-item-web-table.html
true
5798203121010168414
UTF-8
Loaded All Posts No posts found VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU ARCHIVE SEARCH ALL POSTS No post found which matches with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy