Bird
0
0

You wrote cy.get('.btn-primary').click() but the test fails with "element not found" error. What is the most likely cause?

medium📝 Debug Q6 of 15
Cypress - Selecting Elements
You wrote cy.get('.btn-primary').click() but the test fails with "element not found" error. What is the most likely cause?
AThe element has ID 'btn-primary' instead of class
BThe element does not have class 'btn-primary'
CThe selector should be '#btn-primary' for class
Dcy.get() cannot select classes
Step-by-Step Solution
Solution:
  1. Step 1: Check selector correctness

    .btn-primary selects elements with class 'btn-primary'.

  2. Step 2: Identify cause of failure

    If element not found, likely no element has that class in the page.

  3. Final Answer:

    The element does not have class 'btn-primary' -> Option B
  4. Quick Check:

    Selector must match existing element [OK]
Quick Trick: Verify element has the class before selecting [OK]
Common Mistakes:
  • Confusing class and ID selectors
  • Assuming cy.get() can't select classes
  • Typos in class names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes