Pagination can be handled in multiple ways using Selenium and the steps to implement one of the widely used techniques in a professional framework is as mentioned below:
- Step-1: Wait for the page to load properly.
- Step-2: Scroll to the "Next" button.
- Step-3: Wait till the page loads completely.
- Step-4: Use a loop and boolean flags to handle changing values.
Additionally, it is assumed that the element is clickable.
Code Stack
- Step-1: Navigate to the required application
driver.get(application url);
- Step-2: Wait for the page to load
Thread.sleep(10000) //time in ms
- Step-3: Initialize WebDriver to JavascriptExecutor
JavascriptExecutor js = (JavascriptExecutor) driver;
- Step-4: Locating element by link text and storing it in variable "element"
WebElement element = driver.findElement(By.linkText("Required Element"));
- Step-5: Scrolling down the page till the element is found
js.executeScript("arguments[0].scrollIntoView();", element);
- Step-6: Click on the next button
element.click();
- Step-7: Wait for the page to load completely
Thread.sleep(10000) //time in ms
Post a Comment