Bird
0
0

You wrote cy.contains(button, 'Save').click() but the test fails with a syntax error. What is the problem?

medium📝 Debug Q14 of 15
Cypress - Selecting Elements
You wrote cy.contains(button, 'Save').click() but the test fails with a syntax error. What is the problem?
AYou must use cy.get() before cy.contains().
Bcy.contains() cannot be chained with click().
CThe text 'Save' must be uppercase.
DThe selector button should be a string: 'button'.
Step-by-Step Solution
Solution:
  1. Step 1: Check argument types in cy.contains()

    The selector argument must be a string, so 'button' needs quotes.
  2. Step 2: Identify the syntax error cause

    Using button without quotes causes a syntax error because it's treated as a variable.
  3. Final Answer:

    The selector button should be a string: 'button'. -> Option D
  4. Quick Check:

    Selector must be string in cy.contains() [OK]
Quick Trick: Always quote selectors in cy.contains() [OK]
Common Mistakes:
  • Forgetting quotes around selector
  • Thinking click() can't be chained
  • Assuming text case matters in cy.contains()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes