Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda