Reputation: 681
cy.get("tbody > tr")
.first()
.then((el) => {
console.log(el);
el.get("td.edit > button").click();
});
<table>
<tbody>
<tr>
<td>
Lorem ipsum
</td>
<td class="edit">
<button>Button</button>
</td>
<td>
Lorem ipsum
</td>
</tr>
</tbody>
</table>
The above code snippet is from my cypress test where I want to click the button of the first <tr>
tag.
The above test codes the following error.
How can I perform click() operation inside then block ?
Cannot read property 'click' of undefined
Upvotes: 0
Views: 865
Reputation: 18650
You have to use cy.wrap()
cy.get("tbody > tr")
.first()
.then((el) => {
cy.wrap(el).find("td.edit > button").click();
});
Upvotes: 2