Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
How to do `cy.notContains(text)` in cypress?

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')?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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

// code to delete hello

cy.contains('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')
about 4 years ago · Juan Pablo Isaza Report

0

cy.contains('hello').should('not.exist) isn't going to work if there's more that one occurrence of "hello".

You may prefer to check the actual element instance has been removed from the DOM

cy.contains('hello')
  .then($el => {

    // delete the element

    cy.wrap($el)
      .should($el => {
        // has this element been removed? 
        expect(Cypress.dom.isAttached($el)).to.eq(false)
      })
  })
about 4 years ago · Juan Pablo Isaza Report

0

You can use contains with a combination of selector and text. Firstly check it exists and then after deletion check, it doesn't exist.

cy.contains('selector', 'hello').should('exist')
//Actions to perform Deletion
cy.contains('selector', 'hello').should('not.exist')
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!