---
description: What is a Scrollbar? A Scrollbar is a lets you move around screen in horizontal or vertical direction if the current page scroll does not fit the visible area of the screen. It is used to move the win
title: How to Scroll Down or UP Page in Selenium Webdriver
image: https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Scrolling a page in Selenium WebDriver uses the JavascriptExecutor interface to run JavaScript scroll commands, because WebDriver manipulates the DOM directly. Four practical scenarios cover scrolling by pixel, to an element, to the page bottom, and horizontally.

* 📜 **JavascriptExecutor:** Runs JavaScript scroll commands through Selenium WebDriver.
* 🔢 **Scroll by pixel:** window.scrollBy(x,y) moves the page a set number of pixels.
* 🎯 **Scroll to element:** scrollIntoView() scrolls until the target element is fully visible.
* ⬇️ **Scroll to bottom:** scrollTo with document.body.scrollHeight reaches the page end.
* ↔️ **Horizontal scroll:** scrollIntoView also moves sideways to off-screen elements.
* 🧭 **Scrollbar basics:** Scrolling reveals elements that load only when they enter view.

[ Read More ](javascript:void%280%29;) 

![Scroll Down or Up Page in Selenium WebDriver](https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png)

## Scroll in Selenium

To scroll using Selenium, you can use JavaScriptExecutor interface that helps to execute JavaScript methods through Selenium Webdriver

**Syntax:**

JavascriptExecutor js = (JavascriptExecutor) driver;  
   js.executeScript(Script,Arguments);

* Script – This is the JavaScript that needs to execute.
* Arguments – It is the arguments to the script. It’s optional.

## What is a Scrollbar?

A Scrollbar is a lets you move around screen in horizontal or vertical direction if the current page scroll does not fit the visible area of the screen. It is used to move the window up and down.

Selenium Webdriver does not require scroll to perform actions as it manipulates DOM. But in certain web pages, elements only become visible once the user have scrolled to them. In such cases scrolling may be necessary.

Scroll bar is of two type : **Horizontal** and **vertical** scroll bar as shown in below screenshot.

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD1.png)

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD2.png)

**Selenium Script to scroll down the page**

Let’s, see the scroll down a web page using the selenium webdriver with following 4 scenarios :

* Scenario 1: To scroll down the web page by pixel.
* Scenario 2: To scroll down the web page by the visibility of the element.
* Scenario 3: To scroll down the web page at the bottom of the page.
* Scenario 4: Horizontal scroll on the web page.

## Scenario 1: To scroll down the web page by pixel.

**Selenium Script**

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ScrollByPixel {

    WebDriver driver;
    @Test
    public void ByPixel() {
        System.setProperty("webdriver.chrome.driver", "E://Selenium//Selenium_Jars//chromedriver.exe");
        driver = new ChromeDriver();

        JavascriptExecutor js = (JavascriptExecutor) driver;

        // Launch the application		
        driver.get("https://demo.guru99.com/test/guru99home/");

        //To maximize the window. This code may not work with Selenium 3 jars. If script fails you can remove the line below		
        driver.manage().window().maximize();

        // This  will scroll down the page by  1000 pixel vertical		
        js.executeScript("window.scrollBy(0,1000)");
    }
}

**Script Description**: In the above code first we launch the given URL in Chrome browser. Next, scroll the page by 1000 pixels through executeScript. Javascript method ScrollBy() scrolls the web page to the specific number of pixels.

**The syntax of ScrollBy() methods is :**

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

x-pixels is the number at x-axis, it moves to the left if number is positive and it move to the right if number is negative .y-pixels is the number at y-axis, it moves to the down if number is positive and it move to the up if number is in negative .

### RELATED ARTICLES

* [TestNG @Test Priority in Selenium ](https://www.guru99.com/test-case-priority-testng.html "TestNG @Test Priority in Selenium")
* [Desired Capabilities in Selenium WebDriver ](https://www.guru99.com/desired-capabilities-selenium.html "Desired Capabilities in Selenium WebDriver")
* [Object Repository in Selenium ](https://www.guru99.com/object-repository-selenium.html "Object Repository in Selenium")
* [How to Install TestNG in Eclipse ](https://www.guru99.com/install-testng-in-eclipse.html "How to Install TestNG in Eclipse")

Example:

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

**Output analysis :** Here is the output when you execute the above script .

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD3.png)

## Scenario 2: To scroll down the web page by the visibility of the element.

**Selenium Script**

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ScrollByVisibleElement {

    WebDriver driver;
    @Test
    public void ByVisibleElement() {
        System.setProperty("webdriver.chrome.driver", "G://chromedriver.exe");
        driver = new ChromeDriver();
        JavascriptExecutor js = (JavascriptExecutor) driver;

        //Launch the application		
        driver.get("https://demo.guru99.com/test/guru99home/");

        //Find element by link text and store in variable "Element"        		
        WebElement Element = driver.findElement(By.linkText("Linux"));

        //This will scroll the page till the element is found		
        js.executeScript("arguments[0].scrollIntoView();", Element);
    }
}

**Script Description:** In the above code, we first launch the given url in Chrome browser. Next, scroll the page until the mentioned element is visible on the current page. Javascript method scrollIntoView() scrolls the page until the mentioned element is in full view :

js.executeScript("arguments[0].scrollIntoView();",Element );

“arguments\[0\]” means first index of page starting at 0.

Where an ” Element ” is the locator on the web page.

**Output analysis :** Here is the output when you execute the above script .

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD4.png)

## Scenario 3: To scroll down the web page at the bottom of the page.

**Selenium Script**

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ScrollByPage {

    WebDriver driver;
    @Test
    public void ByPage() {
        System.setProperty("webdriver.chrome.driver", "E://Selenium//Selenium_Jars//chromedriver.exe");
        driver = new ChromeDriver();

        JavascriptExecutor js = (JavascriptExecutor) driver;

        // Launch the application		
        driver.get("https://demo.guru99.com/test/guru99home/");

        //This will scroll the web page till end.		
        js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
    }
}

**Script Description :** In the above code, we first launch the given url in Chrome browser. Next, scroll till the bottom of the page. Javascript method scrollTo() scroll the till the end of the page .

js.executeScript("window.scrollTo(0, document.body.scrollHeight)");

“document.body.scrollHeight” returns the complete height of the body i.e web page.

**Output analysis:** Here is the output when you execute the above script.

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD5.png)

## Scenario 4: Horizontal scroll on the web page

**Selenium Script**

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class HorizontalScroll {

    WebDriver driver;
    @Test
    public void ScrollHorizontally() {
        System.setProperty("webdriver.chrome.driver", "E://Selenium//Selenium_Jars//chromedriver.exe");
        driver = new ChromeDriver();

        JavascriptExecutor js = (JavascriptExecutor) driver;

        // Launch the application		
        driver.get("https://demo.guru99.com/test/guru99home/scrolling.html");

        WebElement Element = driver.findElement(By.linkText("VBScript"));

        //This will scroll the page Horizontally till the element is found		
        js.executeScript("arguments[0].scrollIntoView();", Element);
    }
}

**Script Description :** In the above code, we first launch the given url in Chrome browser. Next, scroll the page horizontally until the mentioned element is visible on the current page. Javascript method scrollIntoView() scrolls the page until the mentioned element is in full view :

js.executeScript("arguments[0].scrollIntoView();",Element );

**Output analysis:** Here is the output when you execute the above script.

[](https://www.guru99.com/images/1/120817%5F0811%5FScrollUPorD6.png)

Learn more about [JavaScriptExecutor ](https://www.guru99.com/execute-javascript-selenium-webdriver.html)

## FAQs

⬆️ How do you scroll up a page in Selenium?

Use a negative pixel value with window.scrollBy, for example js.executeScript with window.scrollBy(0,-1000). The negative y-value moves the page upward, opposite to a positive value that scrolls down.

🖱️ Can Selenium scroll without JavascriptExecutor?

Yes. You can send Keys.PAGE\_DOWN, Keys.END, or arrow keys to an element, or use the Actions class in Selenium 4\. JavascriptExecutor remains the most flexible option.

📸 Why is scrolling needed for full-page screenshots?

Browsers capture only the visible viewport, so scripts scroll through the page, capture sections, and stitch them. Scrolling also triggers lazy-loaded images and content before the screenshot.

🤖 Can AI generate Selenium scroll scripts?

Yes. AI assistants produce scrollBy, scrollIntoView, and scrollTo snippets from plain instructions, and explain the pixel math. Review locators and wait conditions before running them in your suite.

🤖 How does AI handle infinite scroll in automated tests?

AI-driven tools detect when new content stops loading, adjust scroll depth dynamically, and wait intelligently for elements. This automates testing of infinite-scroll feeds without hard-coded pixel counts.

🧭 What is the difference between scrollBy and scrollIntoView?

scrollBy moves the page a fixed number of pixels from the current position. scrollIntoView scrolls until a specific element is visible. Use scrollBy for distance and scrollIntoView for targeting elements.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png","url":"https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png","width":"700","height":"250","caption":"How to Scroll Down or UP Page in Selenium Webdriver","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/selenium","name":"Selenium"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html","name":"How to Scroll Down or UP Page in Selenium Webdriver"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#webpage","url":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html","name":"How to Scroll Down or UP Page in Selenium Webdriver","dateModified":"2026-06-29T11:59:20+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta","url":"https://www.guru99.com/author/admin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","url":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","caption":"Krishna Rungta","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Selenium","headline":"How to Scroll Down or UP Page in Selenium Webdriver","description":"What is a Scrollbar? A Scrollbar is a lets you move around screen in horizontal or vertical direction if the current page scroll does not fit the visible area of the screen. It is used to move the win","keywords":"selenium","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta"},"dateModified":"2026-06-29T11:59:20+05:30","image":{"@id":"https://www.guru99.com/images/how-to-scroll-down-or-up-page-in-selenium-webdriver.png"},"copyrightYear":"2026","name":"How to Scroll Down or UP Page in Selenium Webdriver","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How do you scroll up a page in Selenium?","acceptedAnswer":{"@type":"Answer","text":"Use a negative pixel value with window.scrollBy, for example js.executeScript with window.scrollBy(0,-1000). The negative y-value moves the page upward, opposite to a positive value that scrolls down."}},{"@type":"Question","name":"Can Selenium scroll without JavascriptExecutor?","acceptedAnswer":{"@type":"Answer","text":"Yes. You can send Keys.PAGE_DOWN, Keys.END, or arrow keys to an element, or use the Actions class in Selenium 4. JavascriptExecutor remains the most flexible option."}},{"@type":"Question","name":"Why is scrolling needed for full-page screenshots?","acceptedAnswer":{"@type":"Answer","text":"Browsers capture only the visible viewport, so scripts scroll through the page, capture sections, and stitch them. Scrolling also triggers lazy-loaded images and content before the screenshot."}},{"@type":"Question","name":"Can AI generate Selenium scroll scripts?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI assistants produce scrollBy, scrollIntoView, and scrollTo snippets from plain instructions, and explain the pixel math. Review locators and wait conditions before running them in your suite."}},{"@type":"Question","name":"How does AI handle infinite scroll in automated tests?","acceptedAnswer":{"@type":"Answer","text":"AI-driven tools detect when new content stops loading, adjust scroll depth dynamically, and wait intelligently for elements. This automates testing of infinite-scroll feeds without hard-coded pixel counts."}},{"@type":"Question","name":"What is the difference between scrollBy and scrollIntoView?","acceptedAnswer":{"@type":"Answer","text":"scrollBy moves the page a fixed number of pixels from the current position. scrollIntoView scrolls until a specific element is visible. Use scrollBy for distance and scrollIntoView for targeting elements."}}]}],"@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#schema-1125076","isPartOf":{"@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/scroll-up-down-selenium-webdriver.html#webpage"}}]}
```
