Find Row

Let's find the table row with text "Charles" and print its index.

📺 You can watch this recipe explained in the video Find The Table Row With The Given Text And Print Its Indexopen in new window.

<table class="table table-bordered people">
  <thead>
    <tr>
      <th>User</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Cheryl</td>
    </tr>
    <tr>
      <td>Charles</td>
    </tr>
    <tr>
      <td>Darryl</td>
    </tr>
  </tbody>
</table>
cy.contains('tr', 'Charles')
  .invoke('index')
  .then((row) => cy.log(`Found text in row ${row}`))