Bird
0
0

Which of the following is the correct Cypress syntax to assert that an element with id #modal is hidden?

easy📝 assertion Q12 of 15
Cypress - Assertions
Which of the following is the correct Cypress syntax to assert that an element with id #modal is hidden?
Acy.get('#modal').should('not.be.visible')
Bcy.get('#modal').should('not.visible')
Ccy.get('#modal').should('be.hidden')
Dcy.get('#modal').should('not.exist')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct negative visibility assertion

    In Cypress, to check if an element is hidden but still in the DOM, use should('not.be.visible').
  2. Step 2: Check each option's syntax

    cy.get('#modal').should('not.exist') checks for absence, not hidden. cy.get('#modal').should('be.hidden') uses invalid assertion be.hidden. cy.get('#modal').should('not.visible') has incorrect syntax not.visible.
  3. Final Answer:

    cy.get('#modal').should('not.be.visible') -> Option A
  4. Quick Check:

    Hidden element = should('not.be.visible') [OK]
Quick Trick: Use 'not.be.visible' to check hidden elements [OK]
Common Mistakes:
  • Using 'not.exist' to check hidden instead of absent
  • Writing incorrect assertion names like 'be.hidden'
  • Missing 'be' in visibility assertion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes