Home Ask Login Register

Developers Planet

Your answer is one click away!

en74 February 2016

Watir-Webdriver, Ruby - click on the table row

I'm using Watir-Webdriver and Ruby. On the page I have a table of record. I need to click on any row and it should go the next page. How can I click on the row? Here's the source code for each record from the table

<tr class="ng-scope" ng-click="clickHandler({rowItem: item})" ng-repeat="item in ngModel">
<td class="ng-bindging">Sometext</td>
<td class="ng-bindging">Sometext1</td>
<td class="ng-bindging">Sometext2</td>
<td class="ng-bindging">Sometext3</td>
<td class="ng-bindging">Sometext4</td>
<span class="glyphicon glyphicon-play-circle"></span>

Any suggestions would be appreciated.

Thank you.


titusfortner February 2016

The key is to find unique attributes that Watir can access. The first issue is that your angular app doesn't product valid html5 without data- prepended.

I don't know what your other rows look like to know how to click this one versus another one, but if that attribute is unique, you could use css:

browser.element(css: "tr[ng-repeat='item in ngModel']")

If your text is unique you could also do this (even though it is less ideal):

browser.td(text: 'Sometext').parent

Justin Ko February 2016

As you do not care which tr element you click, you could simply click the first tr element in the table:

record_table = browser.table

If the first row is a header row, you might need to click the last row instead:

record_table = browser.table

Note that browser.table will click the first table on the page. If there are more tables on the page, you will want to be more specific - eg browser.table(id: 'some_id').

Post Status

Asked in February 2016
Viewed 3,509 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life