Home > Back-end >  Java Selenium - navigating with the website's page-navigator gets stuck
Java Selenium - navigating with the website's page-navigator gets stuck

Time:12-18

I am trying to move through website pages using the website's page navigator, but it always stops clicking at page 13.

This is the page navigator: enter image description here

This is my code:

for (int i = 1; i <= numOfPages; i  ) {
    customWebDriver.getWebDriver().findElement(By.className("css-3a6490")).click();
    Thread.sleep(3000);
}

This is the HTML structure: enter image description here

I have also tried using the element under css-3a6490, css-15a7b5o:

for (int i = 1; i <= numOfPages; i  ) {
    customWebDriver.getWebDriver().findElement(By.className("css-15a7b5o")).click();
    Thread.sleep(3000);
}

but it also didn't work.

Does someone knows what is the problem? Thanks

CodePudding user response:

Try with:

customWebDriver.getWebDriver().findElement(By.xpath("//button[@class='css-19a323y']//following-sibling::button[1]")).click();

Explanation of Xpath: A button with class css-19a323y (Which is the current selected page) and then selecting the following button (Which is the next available page)

Also use more time for Thread.sleep(3000); because sometimes when you make pagination it takes more time, so better add more time, or using WebdriverWait and Expected conditions, here an example:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));
  • Related