I am testing a web app which contains a div
<div style="overflow: auto; max-height: 429px;" …
which contains a large table. I see scrollbars around the table. Now I want Cypress to click on an element in the table. If the element is hidden somewhere down, that's fine. Cypress will automatically scroll there. But if the element is hidden somewhere on the right, Cypress won't scroll to the correct place but complains:
CypressError: Timed out retrying after 10050ms:
cy.click()
failed because the center of this element is hidden from view: `<input type="radio" …
Why is that? What can I do?
I am using the latest Cypress (13.6.2).
Edit: It turns out there were two different problems:
The first problem happened in wide tables inside "overflow: auto". The second problem happened without any overflow context after I switched the displayBehavior from the default "top" to "center".
At first it is important to understand, that normally Cypress automatically scrolls e. g. before a click()
. The default scrollBehavior
is "top"
.
It turns out there were two different problems:
These two problems need different solutions.
scrollBehavior
to "center"
in cypress.config.ts solved the first problem..scrollIntoView()
e. g.
cy.get("#foo).scrollIntoView().click()
…