Bird
0
0

Given the HTML snippet:

medium📝 Predict Output Q13 of 15
Cypress - Selecting Elements
Given the HTML snippet:
<ul>
  <li class='item'>Apple</li>
  <li class='item'>Banana</li>
  <li class='item'>Cherry</li>
</ul>

What will cy.get('.item').should('have.length', 3) check?
AThat there are exactly 3 elements with class 'item'
BThat the first element with class 'item' contains '3'
CThat the list has 3 child elements regardless of class
DThat the page has 3 lists
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.get('.item')

    This selects all elements with the class 'item', which are the three <li> elements.
  2. Step 2: Understand .should('have.length', 3)

    This asserts that the number of selected elements is exactly 3.
  3. Final Answer:

    That there are exactly 3 elements with class 'item' -> Option A
  4. Quick Check:

    cy.get('.item').length = 3 [OK]
Quick Trick: '.should(have.length, n)' checks number of matched elements [OK]
Common Mistakes:
  • Thinking it checks content inside elements
  • Confusing child count with class count
  • Assuming it checks number of lists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes