The title might be confusing, I didn't know how to put my thoughts into words.
Let me explain that simple example. Given the following table...
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
</table>
... I'd like to:
- Get the index position of
<th>that contains "Contact" (which is1in this case) - Use this index to check if the corresponding cell (
<td>) contains a specific value - in this case, "Maria Anders"
I have no idea how to approach point 1.
I know that I could use
cy.get('th').eq(1).should('contain', 'Contact')
cy.get('td').eq(1).should('contain', 'Maria Anders')
but in my case, table content is dynamic, and I can not expect that the header I am looking for will be under a specific index. Instead, I would like to find the <th> index after the title text.