Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do `cy.notContains(text)` in cypress? [duplicate]

I can check if text exists in cypress with cy.contains('hello'), but now I delete hello from the page, I want to check hello doesn't exist, how do I do something like cy.notContains('hello')?

like image 719
Alien Avatar asked Nov 20 '25 14:11

Alien


1 Answers

For the simple problem of checking 'hello' doesn't exist, you can use .contains('hello') followed a .should(). So it would look something like this for the whole page:

// code to delete hello

cy.contains('.selector', 'hello').should('not.exist')

Or you can further narrow it down to a particular area of the app:

// code to delete hello

cy.get('.element-had-hello').should('not.include.text', 'hello')
like image 142
jjhelguero Avatar answered Nov 23 '25 03:11

jjhelguero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!