I need to scroll down page till end in the Selenium WebDriver. I tried to scroll down the page by using the following code snippet:
JavascriptExecutor jse6 = (Ja
We have to use JavascriptExecutor
To scroll using coordinate
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
To scroll till end of the page
((JavascriptExecutor) driver)
.executeScript("window.scrollTo(0, document.body.scrollHeight)");
To scroll till any element
((JavascriptExecutor) driver).executeScript(
"arguments[0].scrollIntoView();", element);
For this you can take the xpath of any object at the end of the page manually.And use the below code.
WebElement lastElement =
driver.findElement(By.xpath("//a[@title='org.apache.spark download']"));
int y = lastElement.getLocation().getY();
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"+y+")");
Thread.sleep(3000);