Bird
0
0

Which of the following is the correct Cypress syntax to assert that an element with class title has the exact text 'Welcome'?

easy📝 Syntax Q3 of 15
Cypress - Assertions
Which of the following is the correct Cypress syntax to assert that an element with class title has the exact text 'Welcome'?
Acy.get('.title').should('have.text', 'Welcome')
Bcy.get('.title').should('contain.text', 'Welcome')
Ccy.get('.title').should('have.value', 'Welcome')
Dcy.get('.title').should('be.visible', 'Welcome')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct assertion for exact text

    should('have.text', 'Welcome') asserts the element's text exactly matches 'Welcome'.
  2. Step 2: Check other options

    contain.text checks partial text; have.value is for input values; be.visible does not accept text argument.
  3. Final Answer:

    cy.get('.title').should('have.text', 'Welcome') -> Option A
  4. Quick Check:

    Exact text assertion = should('have.text', text) [OK]
Quick Trick: Use should('have.text', text) for exact text match [OK]
Common Mistakes:
  • Using 'contain.text' for exact match
  • Passing text to 'be.visible'
  • Using 'have.value' for non-input elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes