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

188
Views
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
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!