Bird
0
0

Which of the following is the correct syntax to find a button with text 'Login' using cy.contains()?

easy📝 Syntax Q12 of 15
Cypress - Selecting Elements
Which of the following is the correct syntax to find a button with text 'Login' using cy.contains()?
Acy.contains(button, Login)
Bcy.contains('button', 'Login')
Ccy.contains('Login', 'button')
Dcy.contains('button' + 'Login')
Step-by-Step Solution
Solution:
  1. Step 1: Recall cy.contains() syntax with selector

    The correct syntax is cy.contains(selector, text) where selector is a string like 'button'.
  2. Step 2: Match the correct option

    cy.contains('button', 'Login') uses cy.contains('button', 'Login') which is correct. Other options misuse quotes or argument order.
  3. Final Answer:

    cy.contains('button', 'Login') -> Option B
  4. Quick Check:

    cy.contains('selector', 'text') correct syntax [OK]
Quick Trick: Use cy.contains('selector', 'text') to narrow search [OK]
Common Mistakes:
  • Omitting quotes around selector or text
  • Swapping the order of selector and text
  • Concatenating strings incorrectly inside cy.contains()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes