Bird
0
0

Consider this Cypress command:

medium📝 Predict Output Q4 of 15
Cypress - Selecting Elements
Consider this Cypress command:
cy.get('.tab').click()

What happens if there are 5 elements with class tab on the page?
AThe test fails due to multiple elements matching
BCypress clicks all 5 elements sequentially
CCypress clicks the first element with class <code>tab</code>
DCypress throws an error about ambiguous selectors
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.get() behavior

    When multiple elements match, cy.get() yields all but commands like click() act on the first element by default.
  2. Step 2: Effect of click()

    The click() command clicks only the first matched element.
  3. Final Answer:

    Cypress clicks the first element with class tab -> Option C
  4. Quick Check:

    click() acts on first matched element [OK]
Quick Trick: Click acts on first matched element by default [OK]
Common Mistakes:
  • Assuming click triggers on all matched elements
  • Expecting an error due to multiple matches
  • Believing Cypress randomly picks an element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes