How to Scroll Page in Selenium Webdriver using Java Script

Hello, Welcome to Selenium tutorials, in this post we will see Scroll page in Selenium Webdriver using different ways.

JavaScript plays very important role in Selenium Webdriver too, earlier also we have seen how to work with JavaScript and usage of Java Script in Selenium Webdriver.

We can highlight elements as well using JavaScript.

If you are working with Mobile Test Automation using Appium then in mobile devices we have pre-defined method to scroll page


Scroll page in Selenium Webdriver



Before starting, I want to share one more point which will clear your doubts. We have two type of scroll in Selenium.

1- Scroll into view (Kindly check detailed post which covers the complete scenario)

2- Scroll page (Scroll page and Scroll down)


Selenium handle scrolling page automatically but if want to scroll page using Selenium then yes we can do easily using JavaScript.

We have method scroll(horizontal, vertical) i.e. scroll(0,400)


Note- scroll method is not a method of Webdriver, this is a method of JavaScript. 


Scroll page in Selenium Webdriver

To execute JavaScript code inside Selenium script we can take the help of JavascriptExecutor

JavascriptExecutor is an Interface which is available in  package org.openqa.selenium.JavascriptExecutor;

Inside this Interface we have a method called executeScript()– so whatever script you will pass as a string It will be executed by JavascriptExecutor.


Recently I have published video for the same. 



Program to Scroll page in Selenium Webdriver.


Please comment in below section if you have any issue while executing above code

Thanks for visiting my blog. Keep in touch.

Happy Testing. 🙂


For more updates Like our Facebook Page.

For any Selenium related query Join Facebook Group.


  1. sreedhar
  2. Siddharth
  4. Chetan Yeshi