Thursday, 16 January 2014

How to click on the links or buttons in webtable in QTP?

Consider below web table. It has got 4 rows. Now what we have to do is – we have to click on the edit or delete link in front of the given employee.


Employee Name Operation  
Sagar                Edit  / Delete  
Amol                Edit  / Delete  
ajit                        Edit  / Delete


If we try to save links in OR, QTP uses the index property to identify the edit or delete buttons. But using index is not reliable because if new employee is added in the middle index of the existing links will also change.

To handle such situations, we can use html dom. We can solve the problem using below approach.
1. First get the row number in which given employee exists.
2. Then find the links in that row using getElementsByTagName method.
Here is the code to find the row number for the given employee.

function getRow(byval Employee)
Set tableObject = Browser(“MyB”).Page(“Myp”).WebTable("Mytable")
For i=1 to tableObject.object.rows.count
if tableObject.getCellData(i,1) = Employee Then
print "row found " & i
getRow = i
exit function
end if
Next
getRow = -1
End function

Above function will get the rownumber for the given employee. After this we can get the links in front of the given employee using below code.

Set tableObject = Browser(“MyB”).Page(“Myp”).WebTable("Mytable")
Set rowElement = tableObject.object.getElementsByTagName("tr")(rowNumber+1)
set links = rowElement.getElementsByTagName("A")
'Above statement will return all the links inside given row.
if links(0).innerText = "Edit" then
links(0).click()
End If

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.