$show=home$hide=mobile-page

UFT Function to Click Link in Web Table

UFT Function to click link in Web Table based on value present in same or another column in the same row.

UFT Function to click link in Web Table based on value present in same or another column in the same row
UFT Function to click link in Web Table based on value present in same or another column in the same row.

What the function does?

While doing automation on web applications we get scenarios where we have to click a particular link in a web table which has a number of items in it. In some cases these links may be dynamic based on selected filters and all. In such a case it is difficult to click a specific link. This function helps you to click a link based on link text or based on the text available on other columns in the web table.

For example let us consider the following web table with some student data.
Sl. No Student Name Address Progress Report
1 Rahul Address Progress Report
2 Sameer Address Progress Report
3 Austin Address Progress Report
4 Libin Address Progress Report
5 Mahesh Address Progress Report
6 Vineeth Address Progress Report
7 Hareesh Address Progress Report
8 Praveen Address Progress Report
9 Arun Address Progress Report
10 Anu Address Progress Report
As you can see each student listed in the table has individual Address Link and Progress Report Link. So in this case what if you want to click the link against the student Mahesh? Well in such a scenario you can make use of this function.
Function Overview
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

The Function

'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'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 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)

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 Click Link in Web Table
UFT Function to Click Link in Web Table
UFT Function to click link in Web Table based on value present in same or another column in the same row.
https://3.bp.blogspot.com/-CrMLyd0nQtU/WMlOuQvV6QI/AAAAAAAAAHA/CkREXZmDVLsT4_K-nLIzF4t4hCVYIWftACLcB/s320/webtableclick.jpg
https://3.bp.blogspot.com/-CrMLyd0nQtU/WMlOuQvV6QI/AAAAAAAAAHA/CkREXZmDVLsT4_K-nLIzF4t4hCVYIWftACLcB/s72-c/webtableclick.jpg
Aneejian
http://www.aneejian.com/2012/11/uft-qtp-function-to-click-link-in-web-table.html
http://www.aneejian.com/
http://www.aneejian.com/
http://www.aneejian.com/2012/11/uft-qtp-function-to-click-link-in-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