adam
adam

Reputation: 55

how i can click on the second row in a table using protractor

i'm trying to use protractor to click on the second row of a table.

    <!DOCTYPE html>
<html>
<body>

<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

</body>
</html>

so for example if i want to click on the row that contains eve what should i do ?

Upvotes: 0

Views: 2183

Answers (1)

alecxe
alecxe

Reputation: 473823

If you want to click the td element with Eve text, you can do it via "by.cssContainingText":

element(by.cssContainingText("table tr td", "Eve")).click();

If you want to click the parent tr element:

element(by.xpath("//table/tr[td = 'Eve']")).click();

If you don't know if Eve is gonna be there and just need to click the second row in the table:

$$("table tr").get(1).click();  // indexing starts with 0

Upvotes: 2

Related Questions