How to scroll to bottom (ending page) in web selenium

I need to scroll down to the bottom of the page in Selenium WebDriver, I tried to scroll down the page using the JavascriptExecutor jse6 = (JavascriptExecutor); jse6.executeScript ("window.scrollBy (0,250)", "");

but i need to scroll to the bottom of the page

+3


source to share


2 answers


We have to use JavascriptExecutor

To scroll using coordinates

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");

      

To scroll to the end of the page



((JavascriptExecutor) driver)
     .executeScript("window.scrollTo(0, document.body.scrollHeight)");

      

To scroll to any element

((JavascriptExecutor) driver).executeScript(
            "arguments[0].scrollIntoView();", element);

      

+7


source


To do 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);

      

0


source







All Articles