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

280
Vistas
Is there a way in cypress to accomodate cy.get(`[data-cy="${test}"]`).filter(':visible') and cy.get(`[data-cy="${test}"]`) in a single code?

I have a code like

cy.get(`[data-cy="${test}"]`).filter(':visible').click({force: true})

it works for some tests but for some elements there is no "filter" and those works without .filter(':visible'), so i am trying to accomodate both function in a single code to keep it generic for all kinds of buttons. Is there a way to do it?

I have tried few steps like:

cy.get(`[data-cy="${test}"]`).filter(':visible'|| ':hidden').click({force: true})

not sure whether it is right or wrong but its definielt not working!!

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

0

If you are using {force: true} then it doesn't matter if the element is visible or hidden, cypress will click it. So in my opinion you don't need the filter option.

cy.get(`[data-cy="${test}"]`).click({force: true})

Or, If you want to directly apply the OR condition in .filter you can do:

cy.get(`[data-cy="${test}"]`).filter(':visible,:hidden').click({force: true})

Or, If you want to use If-Else you can do something like this:

cy.get(`[data-cy="${test}"]`).then(($ele) => {
  if ($ele.filter(':visible')) {
    cy.wrap($ele).click()
  } else if ($ele.filter(':hidden')) {
    cy.wrap($ele).click({force: true})
  }
})
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