Selenium Webdriver doesn't provide an inbuilt method for page scrolling
By using JavaScript interface we can scroll in Page(Horizontal,Vertical).
We need to import this packege import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ScrollDemo {
public static void main(String[] args) throws Exception {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://facebook.com");
Thread.sleep(5000);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 1500)"); //y value can be altered
Thread.sleep(5000);
JavascriptExecutor jse1 = (JavascriptExecutor)driver;
jse1.executeScript("scroll(250, 0)"); //x value can be altered
}}
Output:First it will scroll down(Y axis) and after 5 seconds it will scroll up(X axis).




