Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
How to scroll page up/down using Selenium Driver in C#?

I am trying to scroll my window up in automated testing environment, but this just does not work (also no errors in console):

public void ScrollToTheTop()
{
    if (this.driver is RemoteWebDriver remoteDriver)
    {
        IJavaScriptExecutor jex = remoteDriver;
        jex.ExecuteScript("window.scrollTo(0,0)");
    }
}

Now if I try to execute jex.ExecuteScript("alert('Something')") it works fine, which means that js gets executed correctly. But for some reason scroll operations do not work (tried scrollBy() aswell).

Does anybody know how to execute scroll scripts? Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to scroll in C#, Using ExecuteScript please use below code :

((IJavaScriptExecutor)Driver).ExecuteScript("window.scrollTo(0, Y)");

Where Y should be vertical axis.

to scroll down :

((IJavaScriptExecutor)Driver).ExecuteScript("window.scrollTo(0, 200)");

or to scroll up :

((IJavaScriptExecutor)Driver).ExecuteScript("window.scrollTo(0, -200)");

To move to a specific web element in C#-Selenium bindings :

IWebElement e = Driver.FindElement(By.XPath(xpath of the web element));
((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].scrollIntoView(true);", e);

to move till end of the page :

((IJavaScriptExecutor)Driver).ExecuteScript("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!