What does the force: true option do in Cypress commands?
It tells Cypress to perform the action even if the element is hidden or covered, bypassing the usual visibility checks.
Click to reveal answer
beginner
Why might you need to use force: true in a test?
Sometimes elements are hidden or overlapped but still need to be interacted with, like hidden buttons or inputs. force: true allows the test to click or type on them anyway.
Click to reveal answer
beginner
Show a simple Cypress command that clicks a hidden button using the force option.
cy.get('#hidden-button').click({ force: true });
Click to reveal answer
intermediate
What is a risk of using force: true in tests?
It can hide real problems in the UI, like elements that should be visible but are not. Overusing it might make tests pass even if the app has bugs.
Click to reveal answer
intermediate
Can force: true be used with commands other than click()? Give an example.
Yes, it can be used with commands like type(). Example: cy.get('input').type('hello', { force: true });
Click to reveal answer
What does { force: true } do in Cypress?
AWaits for the element to become visible
BSkips the test step
CClicks or types on elements even if they are hidden or disabled
DOnly works on visible elements
✗ Incorrect
The force: true option forces Cypress to interact with elements regardless of visibility or state.
Which Cypress command can use force: true?
Atype()
BAll of the above
Ccheck()
Dclick()
✗ Incorrect
Many Cypress commands like click(), type(), and check() support the force: true option.
What is a potential downside of using force: true too often?
ATests might pass even if UI has bugs
BTests run slower
CIt disables assertions
DIt causes syntax errors
✗ Incorrect
Using force: true can hide UI problems because it ignores visibility issues.
If a button is hidden but you want to click it in Cypress, what should you do?
ASkip the test
BUse <code>click()</code> normally
CUse <code>wait()</code> until visible
DUse <code>click({ force: true })</code>
✗ Incorrect
Using click({ force: true }) allows clicking hidden elements.
Does force: true make Cypress ignore if an element is disabled?
AYes, it ignores disabled state
BNo, it only ignores visibility
CNo, it disables the test
DYes, but only for inputs
✗ Incorrect
force: true forces interaction even if the element is disabled or hidden.
Explain when and why you would use the force: true option in Cypress tests.
Think about elements that are not visible but still need testing.
You got /4 concepts.
Describe the risks of overusing force: true in your test suite.
Consider what happens if tests ignore real UI issues.
You got /4 concepts.
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
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.
Step 2: Compare with default behavior
By default, Cypress only interacts with visible elements. Using force: true overrides this.
Final Answer:
Allows Cypress to interact with elements even if they are hidden or not visible. -> Option A
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
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 }.
Step 2: Identify correct syntax among options
cy.get('#submitBtn').click({ force: true }); uses the correct object syntax with curly braces and colon separator.
Final Answer:
cy.get('#submitBtn').click({ force: true }); -> Option D
Quick Check:
Options object uses curly braces and colon [OK]
Hint: Use curly braces and colon for options: { force: true } [OK]
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
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.
Step 2: Verify the assertion outcome
The next line asserts the checkbox is checked, which will be true because the previous command succeeded.
Final Answer:
The test will pass because force allows checking hidden checkboxes. -> Option B
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
Step 1: Identify why the test fails
The button is hidden, so Cypress refuses to click it by default.
Step 2: Apply the force option to override visibility check
Adding { force: true } to the click command forces Cypress to click the hidden button.
Final Answer:
Add { force: true } to the click command. -> Option C
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
Step 1: Understand dropdown visibility and interaction
The dropdown is hidden by default, so normal select won't work without visibility.
Step 2: Use force option to select hidden option
Using { force: true } allows Cypress to select the option even if the dropdown is hidden.
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.
Final Answer:
cy.get('#dropdown').select('Option 1', { force: true }); -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.