What if you could click invisible buttons without lifting a finger?
Why Force option for hidden elements in Cypress? - Purpose & Use Cases
Imagine you are testing a website where some buttons or inputs are hidden behind menus or overlays. You try clicking them manually, but since they are not visible, your clicks don't work. You have to open menus or scroll carefully every time to reach them.
Manually testing hidden elements is slow and frustrating. You might miss clicking some hidden buttons or enter wrong data because the element is not visible. It's easy to make mistakes or waste time trying to find and interact with these hidden parts.
The force option in Cypress lets you interact with hidden elements directly. It tells Cypress to click or type on elements even if they are not visible on the screen. This saves time and avoids errors by skipping the need to reveal elements first.
cy.get('#submit').click(); // Fails if button is hidden
cy.get('#submit').click({ force: true }); // Clicks even if hidden
Using the force option enables smooth, reliable testing of all elements, visible or hidden, without extra steps.
Testing a dropdown menu where the submit button is hidden until you open the menu. Instead of opening the menu manually, you use force to click the submit button directly.
Manual testing hidden elements is slow and error-prone.
Force option lets tests interact with hidden elements easily.
This makes tests faster and more reliable.