Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!