Bird
0
0

Which Cypress assertion checks if an element is present in the DOM, regardless of visibility?

easy📝 Conceptual Q11 of 15
Cypress - Assertions
Which Cypress assertion checks if an element is present in the DOM, regardless of visibility?
A<code>should('contain.text')</code>
B<code>should('be.visible')</code>
C<code>should('have.text')</code>
D<code>should('exist')</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of exist assertion

    The exist assertion checks if the element is present in the DOM, even if it is hidden.
  2. Step 2: Compare with other assertions

    be.visible checks if the element is visible, have.text checks exact text content, and contain.text checks partial text. Only exist fits the question.
  3. Final Answer:

    should('exist') -> Option D
  4. Quick Check:

    Check presence = should('exist') [OK]
Quick Trick: Exist means element is in DOM, visible or not [OK]
Common Mistakes:
  • Confusing 'exist' with 'be.visible'
  • Using 'have.text' to check presence
  • Thinking 'contain.text' checks existence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes