Bird
0
0

Which of the following is the correct syntax to check if an element is visible and contains the text 'Submit' using should() with chaining?

easy📝 Syntax Q12 of 15
Cypress - Assertions
Which of the following is the correct syntax to check if an element is visible and contains the text 'Submit' using should() with chaining?
Acy.get('button').should('visible', 'Submit')
Bcy.get('button').should('be.visible', 'contain', 'Submit')
Ccy.get('button').should('contain', 'Submit').should('visible')
Dcy.get('button').should('be.visible').and('contain', 'Submit')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct chaining syntax

    The correct way is to use should() for the first assertion and and() for chaining additional assertions.
  2. Step 2: Check each option

    cy.get('button').should('be.visible').and('contain', 'Submit') uses should('be.visible') then and('contain', 'Submit'), which is correct syntax. Others misuse parameters or chaining.
  3. Final Answer:

    cy.get('button').should('be.visible').and('contain', 'Submit') -> Option D
  4. Quick Check:

    Use should() then and() for multiple checks [OK]
Quick Trick: Use should() first, then and() to chain assertions [OK]
Common Mistakes:
  • Passing multiple conditions in one should() call incorrectly
  • Using should() multiple times instead of and()
  • Wrong order of chaining

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes