'How to scroll down the page till bottom(end page) in the Selenium WebDriver
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 = (JavascriptExecutor) driver;
jse6.executeScript("window.scrollBy(0,250)", "");
It's being scrolled but I need to scroll down till end page.
Solution 1:[1]
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);
Solution 2:[2]
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);
Solution 3:[3]
do it with python,
import time
time.sleep(2)
drive.execute_script("window.scrollTo(0, document.body.scrollHeight)")
based on @shubham bansal's
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shubham bansal |
| Solution 2 | Pulkit Agrawal |
| Solution 3 | dengST30 |
