How To Scroll Web Page Down Or UP Using Selenium WebDriver

Let’s see how to Scroll Web Page DOWN or UP in this post. There are few ways to scroll Web page up or down using Selenum WebDriver. We are going to see those in this post in detail.

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

Also Read: How To Use JavaScriptExecutor in Selenium


window.scrollBy(xnum, ynum)


  • xnum is a Number
  • Required. How many pixels to scroll by, along the x-axis (horizontal). Positive values will scroll to the right, while negative values will scroll to the left
  • ynum is a Number
  • Required. How many pixels to scroll by, along the y-axis (vertical). Positive values will scroll down, while negative values scroll up

Return Value:

No return value

To Scroll Web page Down using Selenium WebDriver:

In the below example we use 250 pixels for vertical scrolling in order to see how scroll method works

To scroll to the Bottom of the Web Page using Selenium WebDriver:

We get the height of the Body element from the DOM (Document Object Model) and we use the scrollTo() method to scroll to the maximum height of the page:

To Scroll Web page Up using Sleneium WebDriver:

Just modify the pixels value to negative number and pass as the second parameter of the scrollBy() method.

If you are not a regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

Sharing is caring.

Share on facebook
Share on twitter
Share on linkedin

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

1 thought on “How To Scroll Web Page Down Or UP Using Selenium WebDriver”

  1. Very Thank you !! It is very helpful.But now my query is How can we scroll down webpage using web driver sampler in jmeter.

Leave a Comment

Your email address will not be published. Required fields are marked *

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook