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

178
Vistas
Cypress: Using multiple selector wih OR condition

I have multiple login pages as:

First login page

Input element is as:

<input placeholder="name@email.com" class="input" name="email" type="text" value="">

Cypress selector is as follows:

cy.get('input[name="email"]').as('email').click();

Second login page:

Input element is as:

<input id="email" type="email" required="required" class="input">

Cypress selector is as follows:

cy.get('input[id="email"]').as('email').click();

If we notice, the 1st input element has name=email while the 2nd has id=email.
Is there a way to write a cypress selector where it can look for selector input[name="email"] if not found it looks for input[id="email"]?

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

0

Yes, there is. It is called cypress conditional testing according to the docs.

There are a number of ways to get this done as seen in the docs depending on what you may want.

Below is something we can do

  cy.get('input[name="email"]').then(($btn) => {
    if ($btn.length) {
      // do something if it's active
      $btn[0].click();
    } else {
      // do something else
      cy.get('input[id="email"]').as('email').click();
    }
  })
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the comma , to do an OR condition if you are using css selectors. Something like:

cy.get('input[name="email"],input[id="email"]').click()
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