Bird
0
0

Consider this code snippet:

medium📝 Predict Output Q5 of 15
Cypress - Element Interactions
Consider this code snippet:
cy.get('.nav-item').eq(2).click()

What does this command do?
AThrows an error because eq() is invalid
BClicks the second element with class 'nav-item'
CClicks the third element with class 'nav-item'
DClicks all elements with class 'nav-item'
Step-by-Step Solution
Solution:
  1. Step 1: Understand eq() usage

    The eq(2) command selects the element at index 2 (zero-based), which is the third element.
  2. Step 2: Understand click on selected element

    After selecting the third element, .click() clicks it.
  3. Final Answer:

    Clicks the third element with class 'nav-item' -> Option C
  4. Quick Check:

    eq(2) selects third element (zero-based) [OK]
Quick Trick: eq() uses zero-based index to select element [OK]
Common Mistakes:
  • Confusing zero-based index with one-based
  • Thinking eq() clicks all elements
  • Assuming eq() is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes