-
Notifications
You must be signed in to change notification settings - Fork 3
Description
When you try to cy.get('#thing').click()
and the thing is out of the viewport, the test will fail and say something like "Fix this problem, or use {force: true} to disable error checking".
In the past, I've gone ahead and followed that advice, that is until I saw this Stack Overflow answer: https://stackoverflow.com/questions/61321918/make-forcetrue-in-click-function-the-default-behavior
Now, I think I should be scrolling into view before trying to click and only force the click if scrolling into view doesn't work.
// Use when Cypress says the element isn't clickable because it is out of view.
cy.get('#thing').scrollIntoView().click();
// Only use if last resort.
cy.get('#thing').click({force: true});
But is there more to the story?
I know some elements can be in the viewport but hidden by a modal or something, and in that case, you would have to force the click...but you should really close the modal first...so I'm not sure where forcing a click is a good idea but rather it is a shortcut.
Maybe https://docs.cypress.io/api/commands/click#Force-a-click-with-relative-coordinates could be a good reason...but man, the click command has way more features and caveats than I thought.