How to scroll down in Selenium? An Easy-to-understand Guide

May 30, 2026 · 7 min read · Tool Comparison

Blog / Insights /
How to scroll down in Selenium? An Easy-to-understand Guide

How to scroll down in Selenium? An Easy-to-understand Guide

Contributors Updated on

Learn with AI

Linkedin

Facebook

X (Twitter)

Mail

Learn with AI

Here ’ s an easy-to-understand and straight-to-the-point guidebook to scroll down in Selenium.
 

Let ’ s try this tryout example: Scroll to a section on a Wikipedia page and screenshot. We feature the next exam steps:

  1. Open Browser: Launch browser and navigate to ``https: //en.wikipedia.org/wiki/Wikipedia."
  2. Scroll to Element: Scroll to the `` Articles in the 20 largest languages '' caption.
  3. Take Screenshot: Capture a screenshot and save it at the following file itinerary: & nbsp;/Users/hy.nguyen/Downloads/screenshot_of_wiki_page.png.
  4. Close Browser: Close the browser window.

You can customize the element according to your needs.

How to scroll to a specific web ingredient in Selenium?

The command we use is:

((JavascriptExecutor) driver) .executeScript (`` contestation [0] .scrollIntoView (true); '', element);
  • JavascriptExecutorallows Selenium to execute JavaScript require instantly on the browser. It 's particularly useful for actions like scrolling, where Selenium 's built-in method might not be sufficient.
  • scrollIntoView ()method scrolls the page until the specified component is in view. The parameter & nbsp;trueensures that the element is aligned with the top of the aspect.

Here ’ s the total codification:

importation org.openqa.selenium.By; signification org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; importation org.openqa.selenium.WebElement; signification org.openqa.selenium.chrome.ChromeDriver; importation org.openqa.selenium.io.FileHandler; significance java.io.File; import java.io.IOException; public class WikipediaTest {& nbsp; & nbsp; & nbsp; public static emptiness main (String [] args) {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Set up the path to the ChromeDriver & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; System.setProperty (`` webdriver.chrome.driver '', `` /path/to/chromedriver ''); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Launch the Chrome browser & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; WebDriver driver = new ChromeDriver (); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; try {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Navigate to Wikipedia page & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; driver.get (`` https: //en.wikipedia.org/wiki/Wikipedia ''); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Find the element for `` Articles in the 20 large lyric '' legend & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; WebElement constituent = driver.findElement (By.xpath (`` // * [contains (schoolbook (), 'Articles in the 20 largest languages ')] '')); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Scroll to the element & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ((org.openqa.selenium.JavascriptExecutor) driver) .executeScript (`` arguments [0] .scrollIntoView (true); '', element); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Take a screenshot and salvage it & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; File screenshot = ((TakesScreenshot) driver) .getScreenshotAs (OutputType.FILE); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; FileHandler.copy (screenshot, new File (`` /Users/hy.nguyen/Downloads/screenshot_of_wiki_page.png '')); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;} match (IOException e) {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; System.out.println (`` Screenshot seizure failed: `` + e.getMessage ()); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;} finally {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Close the browser & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; driver.quit (); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;} & nbsp; & nbsp; & nbsp;}}

How to scroll down by a certain number of pixels in Selenium?

To scroll down, use:

((JavascriptExecutor) driver) .executeScript (`` window.scrollBy (x, y); '');

The window.scrollBy (x, y)scroll the page by a specified amount of pixel. The parameter x and y are for the horizontal and erect pixel values. For example, if you want to scroll down by 500 pixels and no horizontal scrolling, use “ window.scrollBy (0, 500); ”.
 

Let ’ s check out a full code snippet:

import org.openqa.selenium.JavascriptExecutor; signification org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public course ScrollByPixels {& nbsp; & nbsp; & nbsp; public static void main (String [] args) {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Set the path to your ChromeDriver & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; System.setProperty (`` webdriver.chrome.driver '', `` /path/to/chromedriver ''); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Initialize WebDriver & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; WebDriver driver = new ChromeDriver (); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Open a site & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; driver.get (`` https: //www.example.com ''); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Create an instance of JavascriptExecutor & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; JavascriptExecutor js = (JavascriptExecutor) driver; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Scroll down by 500 pixels (you can change this value) & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; js.executeScript (`` window.scrollBy (0, 500) ''); & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; // Close the browser & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; driver.quit (); & nbsp; & nbsp; & nbsp;}}

How to automatise scroll down action using Katalon?

 

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

Here ’ s how you can also do it in Katalon-a comprehensive automation testing puppet. First, download the latest version of Katalon Studio where you can write no-code/low-code tryout cases with ease.
 

Once you successfully login, you should arrive at the Katalon Studio IDE. Let ’ s start by creating a new tryout cause.


 

Katalon follows the Page Object Model. All test objects are store in a hierarchal fashion: each test object belong to a specific web page, all of which are store in the Object Repository. The advantage of this approach? Since UI elements are disunite from test handwriting, any change in the web application 's UI (e.g., changing an component 's ID) can be updated in just one place—the page object class—rather than across multiple trial cases.

 


 

Let 's bewitch some target with Katalon Spy Web Utility.


 

After specifying which page you want to screen, click Start. Let ’ s try capturing the div of the “Articles in the 20 largest words editions of Wikipedia” chart in the Wikipedia page about Wikipedia. To capture, simply right-click on the element and choose Capture Object. Objects only need to be bewitch erst. From that point onwards, you can well reuse them in any test case.
 


 

Here ’ s our captured objective. Click Save and you now have your test object!
 


 

Now let ’ s craft our test lawsuit by leveraging Katalon ’ s library of keywords to command the system to perform your test steps, include the scrolling activeness. We simply click “ Add ” and take the necessary keywords, which include:

 

  1. Open Browser: launch the browser and navigate to the Wiki page on Wikipedia.
  2. Scroll To Element:scroll to the component we 've just captured. You simply drag-and-drop the object from the Object Repository in thither.
  3. Take Screenshot:guide a screenshot and relieve to the condition file path. & nbsp;
  4. Close Browser:closely and end the session.
     


 

Finally, choose your environs and click Run. Let ’ s conduct a look at how it ’ s all done:
 


 

There is also the & nbsp;Scroll To Position & nbsp;keyword where you can set the & nbsp;x position & nbsp;and y position & nbsp;keyword similar to how it ’ s done in Selenium.
 



Explain

|

FAQs

What are the easiest ways to scroll in Selenium?

+

Two mutual options are:

  • Scroll to a specific element with scrollIntoView ()

  • Scroll by a pel runner with window.scrollBy (x, y)

How do I scroll to a specific web element in Selenium?

+

Use JavaScript execution:

((JavascriptExecutor) driver) .executeScript (`` arguments [0] .scrollIntoView (true); '', element);

This scrolls until the target element is visible;truealigns it to the top of the viewport.

How do I scroll down by a certain act of pixels?

+

Use:

((JavascriptExecutor) driver) .executeScript (`` window.scrollBy (0, 500); '');

xis horizontal pel,yis vertical pel (positiveyscrolls down).

How can I formalize the curlicue worked (example access)?

+

A simple coming is towhorl to the element, then take a screenshot(or verify the element is display) to confirm you landed in the right section—like the guide ’ s Wikipedia “ coil + screenshot ” example.

How can I automatize scroll in Katalon instead of coding it in Selenium?

+

Use built-in keywords such asOpen Browser, Scroll To Element(using an object captured into the Object Repository via Spy/Record utilities),Take Screenshot, and Close Browser. There ’ s alsoScroll To Positionfor x/y scrolling like to pixel-based scrolling.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free