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

124
Vistas
Retry the if statement until the 'Withdrawn' element is found in Cypress
cy.get('body').then(($body) => { 
            if ($body.text().includes('Withdrawn')) {
                cy.contains('Withdrawn')
                .click({force:true})
            } else if ($body.text().includes('More')) { 
                cy.contains('More')
                .click({force:true})
                cy.wait(10000)
                cy.contains('Withdrawn')
                .click({force:true})
              
        })

Hello, I am new the cypress and I wish to repeat the if Statement again until the element 'Withdrawn' is found in the body by clicking on the more button. Can anyone let me know what's the best way about executing this?

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

0

Not sure if this is precisely the correct code, but the idea is to recursively call the code you have for a single iteration.

const clickUntilWithdrawn = ($parent, attempts = 0) => {
  if (attempts > 10) throw 'Failed to find'

  if ($parent.text().includes('Withdrawn')) {
    cy.contains('Withdrawn').click()
    return
  }
  cy.contains('More').should('be.visible').click()
  cy.wait(10000)    // probably can be shorter wait with visibility check above
  
  clickUntilWithdrawn($parent, ++attempts)
}

cy.get('parent-element-of-withdrawn')
  .then($el => clickUntilWithdrawn($el))
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