Click a hidden button using force option
Preconditions (1)
✅ Expected Result: The hidden button is clicked successfully and the expected message 'Button clicked!' is displayed
describe('Force option for hidden elements', () => { beforeEach(() => { cy.visit('/hidden-button-test') }) it('Clicks hidden button using force option and verifies message', () => { // Locate hidden button by id and click with force cy.get('#hidden-btn').click({ force: true }) // Verify the expected message appears cy.get('#message').should('be.visible').and('have.text', 'Button clicked!') }) })
The test visits the page with the hidden button first.
It uses cy.get('#hidden-btn') to find the button by its id.
The { force: true } option is passed to click() to allow clicking even though the button is hidden.
After clicking, the test checks that the message with id message is visible and contains the exact text Button clicked!.
This ensures the hidden button was clicked successfully and triggered the expected UI change.
Now add data-driven testing with 3 different hidden buttons, each showing a different message when clicked
force: true option do in Cypress when interacting with elements?force: trueforce: true overrides this.force: true = interact hidden elements [OK]submitBtn using Cypress?{ force: true }.cy.get('.hidden-checkbox').check({ force: true });
cy.get('.hidden-checkbox').should('be.checked');force: true on hidden checkboxesforce: true allows Cypress to check the checkbox even if it is hidden.cy.get('#hiddenBtn').click();{ force: true } to the click command forces Cypress to click the hidden button.select won't work without visibility.{ force: true } allows Cypress to select the option even if the dropdown is hidden.Pass the test and this pattern moves unknown