Styrow.dev
Question 61 of 64

How To Scroll Web Page Down Or UP Using Selenium WebDriver?

Question

How To Scroll Web Page Down Or UP Using Selenium WebDriver?

Answer

JavaScript scrollBy() method scrolls the document by the specified number of pixels.

Syntax for scrollBy() is

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript(""window.scrollBy(x-pixels,y-pixels)"");

Example:

js.executeScript(""window.scrollBy(0,1000)""); //Scroll vertically down by 1000 pixels