Bird
0
0

What is wrong with this Cypress code snippet?

medium📝 Debug Q7 of 15
Cypress - Element Interactions
What is wrong with this Cypress code snippet?
cy.click().get('.btn')
Acy.click() must be called on a selected element, not directly on cy
BThe selector '.btn' is invalid
CThe commands are in the wrong order but still work
Dcy.get() cannot be chained after cy.click()
Step-by-Step Solution
Solution:
  1. Step 1: Understand command chaining

    cy.click() must be called on an element selected by cy.get() or similar. Calling cy.click() directly on cy is invalid.
  2. Step 2: Check command order

    The correct order is to select element first, then click it. So cy.get('.btn').click() is valid.
  3. Final Answer:

    cy.click() must be called on a selected element, not directly on cy -> Option A
  4. Quick Check:

    click() needs element, not cy alone [OK]
Quick Trick: Always select element before calling click() [OK]
Common Mistakes:
  • Calling click() directly on cy
  • Chaining commands in wrong order
  • Assuming click() works without element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes