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

190
Vistas
How do I scroll to bottom of the page with Javascript but with some delay using selenium c#

Good day, everyone!

I have a web page with lazy loading enabled, and I'd like to scroll to the bottom of the page, but with a wait, so that the new components in the page may be seen.

At the present, I'm trying JavaScript, but it just scrolls to the bottom of the page, which doesn't reveal any new elements, and my tests fail as a result.

Could someone please assist me?

Below Is the code for ScrollToBottom

public static void ScrollToBottom(this IWebDriver Driver)
    {
        
        Driver.ExecuteJavaScript("window.scrollTo({ top:  document.body.scrollHeight, behavior: 'smooth' })");
    }

And Entire code for ScrollUntilNoLazyLoad

public static void ScrollUntilNoLazyLoad(this IWebDriver Driver, string locator = null)
    {
        ThreadHelper.VoidWait(() =>
        {
            var before = Driver.PageSource;
            Driver.ScrollToBottom();
            Thread.Sleep(2000);

            var after = Driver.PageSource;
            if (!before.Equals(after))
                Driver.ExecuteJavaScript("window.scrollBy(0, -250)");
            Thread.Sleep(2000);

            var after2 = Driver.PageSource;
            if (locator.IsNullOrEmpty())
            {
                if (!before.Equals(after2))
                    throw new ArgumentException("due to lazy load new items have been added, scrolling will continue.");
            }
            else
            {
                if (Driver.TryFind(locator, IWebElementState.Displayed, 500).IsNull())
                    throw new ArgumentException("Element is not yet displayed!");
            }
        }, false);
    }
about 4 years ago · Juan Pablo Isaza
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