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

380
Vistas
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 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