Styrow.dev
Question 61 of 82

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


šŸ“² Practice Offline on Mobile: Download the free QA Automation & SDET Prep app on Google Play & App Store.