Bird
0
0

In Cypress, what is the main function of cy.contains() when used in a test script?

easy📝 Conceptual Q1 of 15
Cypress - Selecting Elements
In Cypress, what is the main function of cy.contains() when used in a test script?
ATo assert that an element is visible on the page
BTo locate an element that includes specific text content
CTo submit a form automatically
DTo wait for an element to become clickable
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.contains()

    This command searches the DOM for elements containing the specified text.

  2. Step 2: Purpose

    It helps to find elements by their visible text rather than selectors.

  3. Final Answer:

    To locate an element that includes specific text content -> Option B
  4. Quick Check:

    Text matching locates elements [OK]
Quick Trick: cy.contains() finds elements by visible text [OK]
Common Mistakes:
  • Confusing cy.contains() with assertion commands
  • Using cy.contains() to submit forms directly
  • Assuming cy.contains() waits for clickability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes