Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Learn to scroll down in Selenium C# using JavaScriptExecutor for precise scrolling and effective WebElement interaction.
January 13, 2026
Scrolling is an essential feature in web applications, allowing users to navigate through content that can’t fit within a single view. To ensure a smooth user experience, it’s important to implement effective scrolling techniques. Using Selenium WebDriver, testers can automate scrolling to interact with elements that are not immediately visible, and hence, automation becomes necessary when certain WebElements become accessible only after scrolling down, ensuring that all elements are properly tested and interactable.
Scroll down in Selenium C# can be managed using the JavaScriptExecutor interface, which allows the execution of JavaScript commands directly in the browser. This feature enables precise control over the scrolling behavior, ensuring that elements are accessible and tests cover all relevant scenarios.
JavaScriptExecutor in Selenium allows you to perform page scrolling that Selenium’s standard methods might not handle effectively. The below commands scroll the page by 250 pixels up or down, respectively.
To scroll down the page:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.scrollBy(0,250)", "");
To scroll up the page:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.scrollBy(0,-250)", "");
Before we look at some examples of how to scroll in Selenium C# to perform various actions, let’s set up a new test project.
Below are the few libraries that you need to get started with using scroll down in Selenium C#.

PM> NuGet\Install-Package Selenium.WebDriver -Version 4.22.0
Great, Once you have completed the necessary setup, you will run the tests on a cloud-based platform like TestMu AI. TestMu AI is an automation testing platform that lets you run manual and automated C# testing across 3000+ real devices, browsers, and OS combinations.
It allows you to use frameworks like Selenium, Cypress, Playwright, and more. Additionally, it helps accelerate test cycles by enabling parallel execution of automated C# tests, saving your local machine’s resources.
To learn more about how to perform automation on TestMu AI, watch the video below and get started with your automation tests.
To get started with this platform, you need to gather a few details that are necessary to perform the test.

After generating the automation capabilities, you can copy it and add it to the test class as shown below:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
namespace ScrollAction_SeleniumWebDriver
{
public class ECommerceTests
{
private static IWebDriver driver;
private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
private static readonly string testUrl = "https://ecommerce-playground.lambdatest.io/";
[SetUp]
public void Setup()
{
ChromeOptions capabilities = new ChromeOptions();
capabilities.BrowserVersion = "126.0";
Dictionary<string, object> ltOptions = new Dictionary<string, object>();
ltOptions.Add("username", LT_USERNAME);
ltOptions.Add("accessKey", LT_ACCESS_KEY);
ltOptions.Add("platformName", "Windows 11");
ltOptions.Add("project", "Selenium Scroll");
ltOptions.Add("w3c", true);
ltOptions.Add("plugin", "c#-nunit");
capabilities.AddAdditionalOption("LT:Options", ltOptions);
driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
}
}
}

Code Walkthrough:
Below is the code walkthrough for the above setup to understand how capabilities work.


Understanding and learning how to scroll in Selenium C# is essential for ensuring thorough test coverage across different scenarios. Below are various scrolling scenarios commonly encountered during testing in Selenium C#.
To scroll down in Selenium C# to the bottom of the page, you can use JavaScriptExecutor. This allows you to perform scrolling actions, which is especially useful when testing pages with infinite scrolling or dynamically loaded content.
To better understand how to scroll down in Selenium C# to the bottom of a page, let’s look at an example. For this demonstration, we will use the TestMu AI eCommerce Playground website to perform the scroll actions.
Code Implementation:
Below is the test code responsible for performing the scroll down in Selenium C# to the bottom of a page. The test class will be structured as follows:
[Test]
public void ScrollToTheBottom()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.Navigate().GoToUrl(testUrl);
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
Code walkthrough:
Below is the detailed walkthrough for the above code.
The [TearDown] annotation in NUnit designates a method to run after each test, with the Quit() command closing all instances of the driver.
To learn more about various annotation methods in NUnit and how to use them, follow the blog on NUnit annotation for automation and understand why annotations are important in your test script.
Test Execution:
The execution of the above test code on the TestMu AI platform is recorded and can be seen below.

If you need to scroll down to a specific position on a page, you can use a script to scroll by a precise number of pixels. This technique is useful when you want to scroll down in Selenium C# to a specific position.
Scrolling down to a specific WebElement is like navigating directly to that element. However, using a specific position allows you to scroll anywhere on the page by specifying the number of pixels to scroll.
To better understand how to scroll down in Selenium C# by a specific number of pixels, create a test that opens a web page and scrolls down by 500 pixels.
Code Implementation:
Below is the test code responsible for scrolling down by a specified number of pixels in Selenium C#:
The test class will be structured as follows:
[Test]
public void ScrollByAmount()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.Navigate().GoToUrl(testUrl);
js.ExecuteScript("window.scrollBy(0,500)");
}
Code Walkthrough:
Below is the detailed code walkthrough for the above code.
To ensure a specific element is visible on the page, you need to scroll to that element. First, identify the element using Selenium locators.
Scrolling to a specific WebElement is a useful technique when performing a scroll down in Selenium C#. Instead of scrolling to the bottom of the entire page, you only scroll down to a specific element within the page.
To better understand how to scroll to a specific WebElement in Selenium C#, we will use the same website and demonstrate scrolling to the “Shop Now” button.
To identify the element you want to scroll down to, you can use XPath with the SelectorsHub Chrome extension. Follow these steps:

Code Implementation:
Below is the test code responsible to scroll down in Selenium C# to a specific WebElement:
The test class will be structured as follows:
[Test]
public void ScrollToElement()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.Navigate().GoToUrl(testUrl);
var button = driver.FindElement(By.XPath("//a[@class='btn btn-outline-primary btn-lg']"));
js.ExecuteScript("arguments[0].scrollIntoView();", button);
}
Code Walkthrough:
Below is the detailed code walkthrough for the above code.
To learn more about interacting with WebElements and using various locators for automation testing, watch the video below.
Subscribe to the TestMu AI YouTube Channel to get more tutorial videos related to automation using various testing frameworks like Selenium, Playwright, Cypress, and more.
By default, a page loads at the top, so simply executing a scroll-up script might not show any visible effect. To ensure both scroll actions are visible, you will modify the existing test to include scrolling up after performing the scroll down in Selenium C#. This way, both scrolling actions will be demonstrated during the test execution.
To better understand how to scroll up in Selenium C#, let’s look at an example. For this demonstration, we will use the TestMu AI eCommerce Playground website to perform the scroll actions.
Code Implementation:
Below is the test code responsible for performing the scroll up action in Selenium C#.
The test class will be structured as follows:
[Test]
public void ScrollToTheBottomAndBackToTheTop()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.Navigate().GoToUrl(testUrl);
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
js.ExecuteScript("window.scrollTo(0, -document.body.scrollHeight)");
}
Code Walkthrough:
Below is the detailed code walkthrough for the above code.
Test Execution:
The execution of the above test script on the TestMu AI platform is recorded and can be seen below.

Note: Run tests across 3000+ browsers and OS combinations. Try TestMu AI Now!
To scroll horizontally (left or right) on a page and interact with elements outside the visible area of the browser window, resizing the browser window might be necessary to make the horizontal scroll visible.
To better understand how to scroll horizontally in Selenium C#, let’s look at the example below.

Code Implementation:
Below is the test code responsible for performing horizontal scroll in Selenium C#:
The test class will be structured as follows:
[Test]
public void ScrollHorizontally()
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.Manage().Window.Size = new Size(200, 1500);
driver.Navigate().GoToUrl(testUrl);
js.ExecuteScript("window.scrollBy(50,0)");
}
Code Walkthrough:
Below is the detailed code walkthrough for the above code.
Test Execution:
The execution of the above test script on the TestMu AI platform is recorded and can be seen below.

The above examples use Selenium C# to demonstrate scroll actions. These actions are similar across Selenium C#, Selenium Java, and Selenium Python, with differences in method implementation and syntax specific to each language.
To learn how to perform similar scroll operations in Selenium Java, follow this blog on how to scroll down in Selenium. It explains the different methods used to achieve the same scroll actions.
With this, you now know how to scroll down a page in Selenium C#. In web automation with Selenium, there are times when simple Selenium commands aren’t enough to achieve specific actions. For example, when dealing with web pages that require vertical or horizontal scrolling, or both.
Selenium’s native scrolling capabilities are limited to certain browsers. However, by using JavaScript commands in Selenium tests, you can overcome these limitations. The IJavaScriptExecutor interface provided by Selenium allows you to execute JavaScript commands directly in the browser, enabling you to scroll up, down, horizontally, or to a specific element on the page.
Author
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance