Bird
0
0

What will the following Cypress code select?

medium📝 Predict Output Q13 of 15
Cypress - Selecting Elements
What will the following Cypress code select?
cy.get('.menu').find('li.active')
AAll <code>li</code> elements with class 'active' anywhere on the page
BAll elements with class 'menu' and class 'active'
COnly the first <code>li</code> element with class 'active' on the page
DAll <code>li</code> elements with class 'active' inside elements with class 'menu'
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.get('.menu')

    This selects all elements with class 'menu'.
  2. Step 2: Understand .find('li.active')

    This finds all li elements with class 'active' inside those 'menu' elements.
  3. Final Answer:

    All li elements with class 'active' inside elements with class 'menu' -> Option D
  4. Quick Check:

    get('.menu') then find('li.active') = C [OK]
Quick Trick: get() selects parent, find() filters children inside [OK]
Common Mistakes:
  • Thinking find() searches globally
  • Confusing combined classes with nested elements
  • Assuming only first element is selected
  • Ignoring the chaining order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes