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

383
Visualizações
Selenium Webdriver: Handling pagination using while loop in Javascript

I am automating end-to-end flow for multiple questions, each of which appears on a single page. Now quiz can have 6 questions or more, as the number is not set, neither the limit. However we do have 'NEXT' button which becomes disabled when user is on the last question of the quiz.

I am trying to automate it to first select option and then click on "NEXT" button until it becomes disabled when on the last page using While loop.

Code i have tried is :

const nextButtonDisabled = driver.findElement(By.xpath("//button[@disabled and span/text()='NEXT ']"));
const nextButton = driver.findElement(By.xpath("//button/span[text() = 'NEXT ']"));
const optionButton = driver.findElement(By.xpath("(//input[@type = 'radio'])[3]"));

while(!(Quiz.nextButtonDisabled == true)) {
            
            await utils.click(Quiz.nextButton);
            await utils.click(Quiz.optionButton);
        }

Problem here is that while loop executes even after condition becomes false i.e. "Next" button becomes disabled and it errors out.

about 4 years ago · Juan Pablo Isaza
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