Bird
0
0

Find the mistake in this Cypress test snippet:

medium📝 Debug Q7 of 15
Cypress - Assertions
Find the mistake in this Cypress test snippet:
cy.get('#login').should('not.exist').click()
ATrying to click an element that should not exist causes an error
BThe selector '#login' is invalid
CThe assertion 'not.exist' should be 'not.visible'
DThe click command should come before the assertion
Step-by-Step Solution
Solution:
  1. Step 1: Understand the command sequence

    The test asserts the element with id 'login' does NOT exist, then tries to click it.
  2. Step 2: Identify the logical error

    If the element does not exist, clicking it will cause a runtime error because there is no element to interact with.
  3. Final Answer:

    Trying to click an element that should not exist causes an error -> Option A
  4. Quick Check:

    Cannot click non-existent elements = A [OK]
Quick Trick: Don't interact with elements asserted as not existing [OK]
Common Mistakes:
  • Clicking elements after asserting non-existence
  • Confusing 'not.exist' with 'not.visible'
  • Incorrect selector usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes