Reputation: 2693
I have a table with multiple rows and columns, e.g.:
[email protected] | sometext | link (button)
[email protected] | sometext | link (button)
I want to find [email protected] in the table and in that row I need to click the link.
I tried it this way:
cy.get('table tbody > tr').contains('[email protected]').each(($el, index, $list) => {
$el.find('button');
cy.wrap($el).click();
});
The user is found in the table, that's ok, but it is trying to click that user and not the button, seems the $el.find('button')
is ignored.
can you please help how to achieve this?
Upvotes: 1
Views: 2919
Reputation: 1427
I would use element contains
=> parent
=> find
=> click
. If your selectors are correct this would do the job. Though I would use a more concrete cy.contains('td', '[email protected]')
cy.contains('[email protected]')
.parents('tr')
.find('button')
.click()
Upvotes: 2