Bird
0
0

You want to test a list where each div.card contains a button.delete. How do you click the delete button only inside the second card using cy.find()?

hard📝 Application Q15 of 15
Cypress - Selecting Elements
You want to test a list where each div.card contains a button.delete. How do you click the delete button only inside the second card using cy.find()?
Acy.find('div.card').eq(1).get('button.delete').click()
Bcy.get('div.card').find('button.delete').eq(1).click()
Ccy.get('button.delete').eq(1).click()
Dcy.get('div.card').eq(1).find('button.delete').click()
Step-by-Step Solution
Solution:
  1. Step 1: Select the second card div

    cy.get('div.card').eq(1) selects the second card (index 1).
  2. Step 2: Find the delete button inside that card

    .find('button.delete') searches only inside the selected card.
  3. Step 3: Click the found button

    .click() clicks the delete button inside the second card only.
  4. Final Answer:

    cy.get('div.card').eq(1).find('button.delete').click() -> Option D
  5. Quick Check:

    Get second card, then find button inside it [OK]
Quick Trick: Select parent first with eq(), then find child inside it [OK]
Common Mistakes:
  • Using find before get
  • Selecting button globally then filtering
  • Using eq() after find instead of before

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes