Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda