Bird
Raised Fist0
Cypresstesting~20 mins

Force option for hidden elements in Cypress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Force Click Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the test result when clicking a hidden button without force option?

Consider this Cypress test code snippet:

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

The button with id hidden-btn is hidden via CSS (display: none;).

What will be the outcome of this test step?

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

Think about Cypress default behavior when interacting with hidden elements.

❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies a hidden element is clicked using force option?

You want to click a hidden button and then check if a message appears.

Which assertion correctly verifies the message after clicking the hidden button with force: true?

Cypress
cy.get('#hidden-btn').click({ force: true })
// Which assertion below is correct?
Acy.get('#message').should('have.text', '')
Bcy.get('#message').should('be.visible').and('contain', 'Clicked!')
Ccy.get('#message').should('be.hidden').and('contain', 'Clicked!')
Dcy.get('#message').should('not.exist')
Attempts:
2 left
💡 Hint

After clicking, the message should appear and be visible.

🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail despite using force option?

Review the test code:

cy.get('#hidden-btn').click({ force: true })
cy.get('#result').should('contain', 'Success')

The button is hidden but the test fails at the assertion step.

What is the most likely reason?

Cypress
cy.get('#hidden-btn').click({ force: true })
cy.get('#result').should('contain', 'Success')
AThe button is disabled, so force click does not trigger the event
BThe force option disables the click event entirely
CThe selector '#result' is incorrect and does not match any element
DThe click event is not wired correctly, so no result update happens
Attempts:
2 left
💡 Hint

Force click bypasses visibility but does not fix event wiring.

❓ framework
advanced
2:00remaining
How does Cypress handle the force option internally when clicking hidden elements?

Which statement best describes what Cypress does when { force: true } is passed to the click() command on a hidden element?

ACypress throws an error but ignores it and continues the test
BCypress makes the element visible temporarily, clicks it, then hides it again
CCypress bypasses visibility checks and triggers the native click event directly on the element
DCypress scrolls the element into view and waits for it to become visible before clicking
Attempts:
2 left
💡 Hint

Think about how force click differs from normal click behavior.

🧠 Conceptual
expert
2:00remaining
What is a potential risk of using force option on hidden elements in tests?

Using { force: true } to click hidden elements can cause which of the following issues in your test suite?

ATests may pass even though the user cannot interact with the element in real usage
BTests will always fail because force option disables event handlers
CTests become slower because force option waits for animations
DTests will skip all assertions after a forced click
Attempts:
2 left
💡 Hint

Consider the difference between test simulation and real user experience.

Practice

(1/5)
1. What does the force: true option do in Cypress when interacting with elements?
easy
A. Allows Cypress to interact with elements even if they are hidden or not visible.
B. Prevents Cypress from clicking on disabled buttons.
C. Automatically waits for elements to become visible before interacting.
D. Skips the test if the element is not visible.

Solution

  1. Step 1: Understand the purpose of force: true

    This option tells Cypress to ignore visibility checks and interact with elements even if they are hidden.
  2. Step 2: Compare with default behavior

    By default, Cypress only interacts with visible elements. Using force: true overrides this.
  3. Final Answer:

    Allows Cypress to interact with elements even if they are hidden or not visible. -> Option A
  4. Quick Check:

    force: true = interact hidden elements [OK]
Hint: Force option lets you click hidden elements safely [OK]
Common Mistakes:
  • Thinking force waits for visibility
  • Assuming force disables tests on hidden elements
  • Confusing force with automatic retries
2. Which of the following is the correct syntax to click a hidden button with id submitBtn using Cypress?
easy
A. cy.get('#submitBtn').click(force=true);
B. cy.get('#submitBtn').click(force:true);
C. cy.get('#submitBtn').click({ force = true });
D. cy.get('#submitBtn').click({ force: true });

Solution

  1. Step 1: Recall correct object syntax for options

    Cypress expects options as an object inside curly braces with key-value pairs, e.g., { force: true }.
  2. Step 2: Identify correct syntax among options

    cy.get('#submitBtn').click({ force: true }); uses the correct object syntax with curly braces and colon separator.
  3. Final Answer:

    cy.get('#submitBtn').click({ force: true }); -> Option D
  4. Quick Check:

    Options object uses curly braces and colon [OK]
Hint: Use curly braces and colon for options: { force: true } [OK]
Common Mistakes:
  • Using parentheses instead of braces for options
  • Using equal sign instead of colon
  • Missing braces around options
3. Consider this Cypress code snippet:
cy.get('.hidden-checkbox').check({ force: true });
cy.get('.hidden-checkbox').should('be.checked');

What will be the result of this test?
medium
A. The test will fail because the checkbox is hidden.
B. The test will pass because force allows checking hidden checkboxes.
C. The test will throw a syntax error.
D. The test will skip the check assertion.

Solution

  1. Step 1: Understand the effect of force: true on hidden checkboxes

    Using force: true allows Cypress to check the checkbox even if it is hidden.
  2. Step 2: Verify the assertion outcome

    The next line asserts the checkbox is checked, which will be true because the previous command succeeded.
  3. Final Answer:

    The test will pass because force allows checking hidden checkboxes. -> Option B
  4. Quick Check:

    force: true lets hidden checkbox be checked [OK]
Hint: Force lets you check hidden checkboxes successfully [OK]
Common Mistakes:
  • Assuming hidden elements cannot be checked
  • Confusing force with visibility wait
  • Expecting syntax errors from correct code
4. You wrote this Cypress test:
cy.get('#hiddenBtn').click();

It fails because the button is hidden. How can you fix it without changing the HTML?
medium
A. Use cy.get('#hiddenBtn').click({ wait: true });
B. Add .should('be.visible') before clicking.
C. Add { force: true } to the click command.
D. Change the selector to a visible element.

Solution

  1. Step 1: Identify why the test fails

    The button is hidden, so Cypress refuses to click it by default.
  2. Step 2: Apply the force option to override visibility check

    Adding { force: true } to the click command forces Cypress to click the hidden button.
  3. Final Answer:

    Add { force: true } to the click command. -> Option C
  4. Quick Check:

    Force option overrides hidden element click failure [OK]
Hint: Use force: true to click hidden elements without HTML changes [OK]
Common Mistakes:
  • Adding visibility assertion before click (won't fix hidden)
  • Using invalid option like wait: true
  • Changing selectors instead of fixing interaction
5. You want to test a hidden dropdown menu that appears only on hover. The dropdown is hidden by default. Which Cypress command correctly selects an option inside it?
hard
A. cy.get('#dropdown').select('Option 1', { force: true });
B. cy.get('#dropdown').select('Option 1');
C. cy.get('#dropdown').invoke('show').select('Option 1');
D. cy.get('#dropdown').click().select('Option 1');

Solution

  1. Step 1: Understand dropdown visibility and interaction

    The dropdown is hidden by default, so normal select won't work without visibility.
  2. Step 2: Use force option to select hidden option

    Using { force: true } allows Cypress to select the option even if the dropdown is hidden.
  3. Step 3: Evaluate other options

    cy.get('#dropdown').select('Option 1'); fails due to hidden dropdown. cy.get('#dropdown').invoke('show').select('Option 1'); tries to show dropdown via invoke but may not trigger UI properly. cy.get('#dropdown').click().select('Option 1'); clicks dropdown but does not guarantee visibility or selection.
  4. Final Answer:

    cy.get('#dropdown').select('Option 1', { force: true }); -> Option A
  5. Quick Check:

    Select hidden dropdown option using force: true [OK]
Hint: Use select with force: true for hidden dropdowns [OK]
Common Mistakes:
  • Trying to select without force on hidden dropdown
  • Using invoke('show') without proper UI event
  • Clicking dropdown without ensuring visibility
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard