How to search and click a link in a WebTable?
Often, we come across some scenario where we have to search some specific “text” which
is link in property, and wants to click it. So, here is the awesome vba function
for you to solve the problem
1. Copy Paste this piece of code in your function library (For example Test.qfl)
Function FindTextAndClickLinkInWebTable(ByVal TestObject, ByVal FindText, ByVal FindTextInColumn, ByVal LinkColumn)
'in case of any errors
On Error Resume Next
'checking whether the object exist
ObjectExist = TestObject.Exist(15)
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
searchEEtext = Trim(TestObject.GetCellData(CRow, FindTextInColumn))
If FindText = searchEEtext 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
TmdbCheckpointMessage "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
TmdbQtpCheckpointFailMessage "Cannot Find Specified Text", "Cannot find the text " & FindText & " in the object specified in function call."
End If
ElseIf Not ObjectExist Then
'reporting error if the specified object is not found
TmdbQtpCheckpointFailMessage "Cannot Find The Object", "Object specified in function call cannot be found."
End If
End Function
RegisterUserFunc "WebTable", "SearchTextAndClickLink", "SearchTextAndClickLink",False
2. Associate the Test.qfl with your current test
Comments
Post a Comment