8

Can someone help me with this Cypress error?

Cypress Error: Timed out retrying: expected '<div.sub-categories-list>' to be '0 visible'

This element '<div.sub-categories-list>' is not visible because it has CSS property: 'position: fixed' and its being covered by another element:

undefined
Diogo Rocha
  • 9,759
  • 4
  • 48
  • 52
ARPITA srivastava
  • 101
  • 1
  • 1
  • 3

2 Answers2

15

The element you are asserting is not visible within the viewport and probably have to be scrolled to in order to be visible.

Cypress do not automatically scroll to elements during the test run, but you can use scrollIntoView(), so write your assertion like this:

cy.get('#yourElement')
    .scrollIntoView()
    .should('be.visible')
Diogo Rocha
  • 9,759
  • 4
  • 48
  • 52
  • 1
    It does not work because `scrollIntoView` does not scroll to the element. Focus stays on the view where it is. The (dirty) workaround `{ force: true }` helps. [My site](https://my-first-servless.netlify.app) to test with cypress. – Timo Aug 05 '22 at 05:58
  • scrollIntoView() is works for me. – Athena Chen Jun 02 '23 at 17:48
3

try to change css attribute/class of the element which is covering your desired element.

cy.get("#coveringElement").invoke('addclass','hidden');
cy.get('#yourDesiredElement');

add the hidden class to all those which are covering your element.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • This does not work, I cannot find in the cypress [docs for `invoke`](https://docs.cypress.io/api/commands/invoke) the `addclass` prop. – Timo Aug 05 '22 at 05:56