Bird
0
0

Why does this Cypress test fail?

medium📝 Debug Q7 of 15
Cypress - Selecting Elements
Why does this Cypress test fail?
cy.get('button.submit').click()

When the button has classes 'submit' and 'btn-primary' but no 'button' tag?
ASelector expects a <button> tag with class 'submit', but the element is not a button tag
BThe class 'submit' is misspelled
CThe click command is missing parentheses
DCypress cannot click elements with multiple classes
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the selector 'button.submit'

    This selector looks for a
  2. Step 2: Check element tag and classes

    The element has class 'submit' but is not a
  3. Final Answer:

    Selector expects a <button> tag with class 'submit', but the element is not a button tag -> Option A
  4. Quick Check:

    Tag + class selector requires matching tag type [OK]
Quick Trick: Match tag and class exactly in selectors [OK]
Common Mistakes:
  • Assuming class selector ignores tag type
  • Thinking click needs parentheses
  • Believing Cypress can't handle multiple classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes