Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Cypress: Check if Select Option Exists

I'm trying to check if there is an option in my select using the code below, but it keeps failing, can somenone give some help?

My Select have about 70 names and I'm trying to loop all them looking for the specific name.

        cy.get('[id="names"] option').each(($ele) => {
            expect($ele).to.have.text('Have This Name')
          })

Thanks in advance,

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would not use .each(), only one will pass but any other will fail.

Use .contains() if your text is specific enough (not in multiple options)

cy.contains('[id="names"] option', 'Have This Name')  // fails only if 
                                                      // no option has the text

If you have to match exactly, filter the options

cy.get('[id="names"] option')
  .filter((idx, el) => el.innerText === 'Have This Name')  // fails if filter 
                                                           // returns 0 items

If you want .each() for another reason, this will do

let found;
cy.get('[id="names"] option')
  .each(($option) => {
    if ($option.text() === 'Have This Name') {
      found = $option
      return false // return now, have found it
    }
  })
  .then(() => {    // after loop exit
    expect(found).to.have.text('Have This Name')
  })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda