0
0
Cypresstesting~20 mins

Hidden elements handling in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hidden Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Cypress test when clicking a hidden button?

Consider the following Cypress test code snippet:

cy.get('#hidden-btn').click()

The button with id hidden-btn is styled with display: none;. What will happen when this test runs?

Cypress
cy.get('#hidden-btn').click()
AThe test skips the click and passes
BThe test passes and clicks the hidden button successfully
CThe test fails with an error: element is not visible
DThe test times out waiting for the button to become visible
Attempts:
2 left
💡 Hint

Think about how Cypress handles clicks on elements that are not visible.

assertion
intermediate
2:00remaining
Which assertion correctly verifies a hidden element is not visible?

You want to check that an element with class .secret-message is hidden on the page. Which Cypress assertion is correct?

Acy.get('.secret-message').should('not.be.visible')
Bcy.get('.secret-message').should('be.hidden')
Ccy.get('.secret-message').should('be.invisible')
Dcy.get('.secret-message').should('not.exist')
Attempts:
2 left
💡 Hint

Check Cypress documentation for visibility assertions.

🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail when trying to type into a hidden input?

Given this test code:

cy.get('#hidden-input').type('hello')

The input with id hidden-input has visibility: hidden;. The test fails. Why?

Cypress
cy.get('#hidden-input').type('hello')
AThe input is disabled, so typing is blocked
BCypress cannot type into elements that are not visible
CThe selector is incorrect and does not find the input
DThe input is readonly, preventing typing
Attempts:
2 left
💡 Hint

Consider Cypress's rules about interacting with hidden elements.

framework
advanced
2:00remaining
How to force Cypress to click a hidden element?

You want to click a button that is hidden with display: none;. Which Cypress command option allows clicking it anyway?

Acy.get('#btn').click({ force: true })
Bcy.get('#btn').click({ allowHidden: true })
Ccy.get('#btn').click({ hidden: true })
Dcy.get('#btn').click({ visible: false })
Attempts:
2 left
💡 Hint

Look for the Cypress click option that overrides visibility checks.

🧠 Conceptual
expert
3:00remaining
What is the best practice to test hidden elements in Cypress?

Which approach is best to test the presence and state of hidden elements in Cypress?

AUse <code>should('not.exist')</code> to confirm element is hidden
BUse <code>invoke('show')</code> to make element visible before testing
CUse <code>should('be.visible')</code> and then check CSS <code>display</code> property manually
DUse <code>should('exist')</code> to check presence and <code>should('not.be.visible')</code> to confirm hidden state
Attempts:
2 left
💡 Hint

Think about how to verify an element is present but hidden.