Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda