Bird
0
0

What is the expected behavior of this Cypress command?

medium📝 Predict Output Q4 of 15
Cypress - Selecting Elements
What is the expected behavior of this Cypress command?
cy.contains('Cancel').click()
AFinds the first element containing 'Cancel' and clicks it
BClicks all elements containing the text 'Cancel'
CThrows an error because 'Cancel' is not a selector
DWaits for an element with id 'Cancel' and clicks it
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cy.contains('Cancel')

    This finds the first DOM element containing the text 'Cancel'.

  2. Step 2: The click() command

    Clicks the found element.

  3. Final Answer:

    Finds the first element containing 'Cancel' and clicks it -> Option A
  4. Quick Check:

    cy.contains() targets first match [OK]
Quick Trick: cy.contains() clicks first matching element [OK]
Common Mistakes:
  • Assuming click() affects all matching elements
  • Thinking 'Cancel' is treated as a selector
  • Expecting cy.contains() to wait for an element by id

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes