I have a web page which is very long and there is a footer on the bottom. To see the footer I have to scroll down. I want to write a cypress test to make sure that the footer is not visible when a user is on the top of the page. To do that I write such code:
cy
.get('#footer')
.should('not.be.visible')
And it fails although it is in fact not on the screen, but below the visible part of the page.
We can check if these elements exist on the webpage in the following way: cy. get('body') .
Get Element By Containing Text in Cypress You can simply use the contains() function along with the tag name and should be able to get the element. Note: The above example we are using contains() for <a> element, but you can use it for any element if you want to find the attribute or perform an action using text.
The assertion be.visible
is designed to check if the user is able to interact with an element even if she has to scroll down to it.
But you can add and use a custom assertion isInViewport
, have a look at https://github.com/cypress-io/cypress/issues/877#issuecomment-490504922.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With