Bird
0
0

You want to test a list where each li has a button inside. Which Cypress code correctly clicks the button inside the third li element within a ul with class 'items'?

hard📝 Application Q15 of 15
Cypress - Selecting Elements
You want to test a list where each li has a button inside. Which Cypress code correctly clicks the button inside the third li element within a ul with class 'items'?
Acy.get('ul.items').eq(2).find('li button').click()
Bcy.get('ul.items').find('li').eq(2).find('button').click()
Ccy.get('ul.items li button').eq(3).click()
Dcy.get('ul.items').find('button').eq(2).click()
Step-by-Step Solution
Solution:
  1. Step 1: Select the parent list

    cy.get('ul.items') selects the ul with class 'items'.
  2. Step 2: Find all li children and pick the third

    .find('li').eq(2) selects the third li (index starts at 0).
  3. Step 3: Find the button inside that li and click

    .find('button').click() clicks the button inside the selected li.
  4. Final Answer:

    cy.get('ul.items').find('li').eq(2).find('button').click() -> Option B
  5. Quick Check:

    Parent get, child find, eq(2), then find button [OK]
Quick Trick: Use eq(2) after finding li, then find button inside [OK]
Common Mistakes:
  • Using eq(3) instead of eq(2) (index off by one)
  • Selecting button before li
  • Using eq on wrong element
  • Not chaining find() properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes