Bird
0
0

What does cy.contains('Submit') do in a Cypress test?

easy📝 Conceptual Q11 of 15
Cypress - Selecting Elements
What does cy.contains('Submit') do in a Cypress test?
AFinds the first element containing the visible text 'Submit'.
BClicks the button named 'Submit' automatically.
CTypes 'Submit' into an input field.
DChecks if the page URL contains the word 'Submit'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.contains() basic function

    The command searches the page for an element that has visible text matching the given string.
  2. Step 2: Analyze the given text 'Submit'

    It finds the first element that contains the text 'Submit' anywhere inside it.
  3. Final Answer:

    Finds the first element containing the visible text 'Submit'. -> Option A
  4. Quick Check:

    cy.contains('text') finds element by visible text [OK]
Quick Trick: cy.contains() finds elements by visible text quickly [OK]
Common Mistakes:
  • Thinking cy.contains() clicks automatically
  • Confusing cy.contains() with typing commands
  • Assuming it checks URL instead of page content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes