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

379
Views
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
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!