0
0
Cypresstesting~5 mins

Hidden elements handling in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean when an element is 'hidden' in web testing?
A hidden element is present in the page's HTML but not visible to the user, often due to CSS styles like display: none or visibility: hidden.
Click to reveal answer
intermediate
How can Cypress interact with hidden elements?
By default, Cypress commands like click() only work on visible elements. To interact with hidden elements, you can use options like { force: true } to force the action.
Click to reveal answer
intermediate
Why should you be careful when forcing actions on hidden elements?
Forcing actions on hidden elements can cause tests to pass even if the user cannot interact with those elements, which may hide real usability problems.
Click to reveal answer
beginner
Which Cypress command checks if an element is visible or hidden?
You can use .should('be.visible') to check visibility or .should('not.be.visible') to check if an element is hidden.
Click to reveal answer
beginner
What is a common real-life example of a hidden element in web apps?
A dropdown menu that only appears when you hover or click a button is hidden by default and becomes visible on user interaction.
Click to reveal answer
In Cypress, how do you click a hidden button?
AUse <code>cy.get('button').click()</code> without options
BUse <code>cy.get('button').should('be.visible').click()</code>
CUse <code>cy.get('button').click({ force: true })</code>
DHidden buttons cannot be clicked in Cypress
Which CSS property commonly hides elements from view but keeps them in the DOM?
Avisibility: hidden
Bdisplay: none
Copacity: 0
Dposition: absolute
What does cy.get('selector').should('not.be.visible') check?
AElement is hidden or not visible
BElement is visible
CElement is disabled
DElement is not in the DOM
Why might forcing clicks on hidden elements be risky in tests?
AIt slows down the test execution
BIt causes Cypress to crash
CIt is not supported by Cypress
DIt can hide real user interface problems
Which Cypress command helps you check if an element is visible before interacting?
Acy.get('selector').click({ force: true })
Bcy.get('selector').should('be.visible')
Ccy.get('selector').invoke('hide')
Dcy.get('selector').wait()
Explain how Cypress handles hidden elements and how you can interact with them safely.
Think about visibility checks and forced actions.
You got /4 concepts.
    Describe a real-life example of a hidden element on a website and how you would test it with Cypress.
    Consider common UI patterns that hide elements.
    You got /4 concepts.