1
<ul class="ItemList">
  <li class="Item" data-id="2"><label><input type="checkbox" value="on"><span>bb</span><button type="button">X</button></label></li>
  <li class="Item" data-id="3"><label><input type="checkbox" value="on"><span>aaa</span><button type="button">X</button></label></li>
</ul>

from the above list I need to select second item and select the check box.

3
  • What have you tried and what exactly is the problem with it? Commented Aug 11, 2019 at 17:45
  • I am new to Cypress. Want to click on X button based on the <span>aaa</span> element or based on row number Commented Aug 12, 2019 at 15:20
  • That doesn't answer my question. Did you read the docs? Try anything? Commented Aug 12, 2019 at 15:20

1 Answer 1

2

You can do this:

cy.contains('aaa')
  .parent()
  .find('input')
  .check()

This will search for the text of the second checkbox, then gets the parent and searches for an 'input' within that parent. And check it after all.

If you want to click the 'X' per element it's just as easy:

cy.contains('aaa')
  .parent()
  .find('button')
  .click()
Sign up to request clarification or add additional context in comments.

2 Comments

Please can you help me to click on X button based on the <span>aaa</span> element or any row
I expanded the answer with the button click. Please accept the answer (by hitting the ^ beside it) if an answer pleases you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.