Bird
0
0

You want to select the third li element inside a ul with class menu. Which cy.get() selector is correct?

hard📝 Application Q8 of 15
Cypress - Selecting Elements
You want to select the third li element inside a ul with class menu. Which cy.get() selector is correct?
Acy.get('ul.menu li:nth-child(3)')
Bcy.get('ul.menu > li:nth-of-type(3)')
Ccy.get('ul.menu li:nth-of-type(2)')
Dcy.get('ul.menu li:nth-child(4)')
Step-by-Step Solution
Solution:
  1. Step 1: Understand nth-child selector

    nth-child(3) selects the third child element regardless of type.

  2. Step 2: Match selector to requirement

    ul.menu li:nth-child(3) selects the third

  3. inside
Quick Trick: Use nth-child(n) to select nth element [OK]
Common Mistakes:
  • Using wrong nth index
  • Confusing nth-child and nth-of-type
  • Selecting wrong element type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes