Skip to content

Cypress select does not have value

I´m writing a Cypress test in which I want to confirm that a certain value is not shown. I want to check that my select element does not have an option with a certain value.

An example:

<select>
 <option>A</option>
 <option>B</option>
</select>

So now I want to check that there isn´t an option with value “C”

cy.get('select') // <-- here I want to verify that option "C" doesn´t exist

Can someone help me evaluate this?

Thanks.

Answer

Try this:

cy.get('select option:contains(C)').should('not.exist')