Table cell index

📺 Watch this recipe explained in the video Find Table Column Indexopen in new window.

<table class="as-table table table-bordered">
      <th>First Name</th>
      <th>Last Name</th>

Invoke the jQuery .index() method to confirm the "Age" column is 3rd in this table. Index starts at zero.

cy.contains('th', 'Age').invoke('index').should('equal', 2)

Find a cell by text and confirm its index.

cy.contains('tbody td', 'Jill')
  .should('equal', 0)

See also