Skip to content
Advertisement

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.

Advertisement

Answer

Try this:

cy.get('select option:contains(C)').should('not.exist')
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement