Bird
0
0

Why does this code fail?

medium📝 Debug Q7 of 15
Cypress - Selecting Elements
Why does this code fail?
cy.contains('Submit').click().click()
ABecause click() returns void, chaining second click() causes error
BBecause cy.contains() cannot be chained
CBecause 'Submit' text is not found
DBecause click() can only be called once per element
Step-by-Step Solution
Solution:
  1. Step 1: Understand chaining behavior of click()

    In Cypress, click() yields void (no subject for further commands), so chaining another click() causes an error.
  2. Step 2: Analyze failure reason

    Chaining two clicks without re-querying element causes error. Other options are incorrect because chaining cy.contains() is valid and text presence is not the issue.
  3. Final Answer:

    Because click() returns void, chaining second click() causes error -> Option A
  4. Quick Check:

    click() chaining requires re-querying element [OK]
Quick Trick: Chain click() once; re-query element for multiple clicks [OK]
Common Mistakes:
  • Chaining multiple clicks without re-query
  • Assuming cy.contains() cannot chain
  • Blaming missing text for chaining errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes