Issue
i have the following HTML
<li data-testid="wrapper">
<div class="selections">
<p data-testid="selection1">
<p data-testid="selection2">
<p data-testid="selection3">
...
<p data-testid="selectionN">
</div>
<button type="button" data-testid="button"></button>
</li>
there are multiple wrappers with different amount of selections. I want to click the button on the first wrapper with exactly 3 selections
Solution
Apply a .filter()
with a jQuery expression:
cy.get('li[data-testid="wrapper"]')
.filter((i,li) => Cypress.$(li).find('p').length === 3 )
.first()
.click()
These alternatives also work:
.filter((i,li) => Cypress.$(li).find('.selections').children().length === 3 )
.filter((i,li) => Cypress.$(li).find('[data-testid^="selection"]').length === 3 )
Answered By - Blondie
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.