Free tools Windows power users keep installed
One-click scans. No signup required.
To capture an infinite-scroll page with Selenium in C#, repeatedly scroll the page—or its actual scrollable container—wait for new content, and stop when the site signals the end or content stops changing. Then save a screenshot. Selenium does not provide a universal infinite-scroll stitching call: for one tall image, capture overlapping viewport segments and stitch them with separate image-processing code.
What you need before capturing
Use a Selenium .NET WebDriver configured for the browser you want to automate. Selenium’s first-script guide shows the basic .NET pattern with IWebDriver and ChromeDriver. Keep Selenium, browser, and driver versions compatible; the official downloads page listed Selenium .NET 4.49.0, released September 9, 2026, when checked for this article.
As an Amazon Associate I earn from qualifying purchases.
Before writing the loop, determine what scrolls on the target site. Some feeds scroll the browser window; others scroll an inner element such as a results panel. Inspect the page and use the correct target. The selector and the condition that means “more content has loaded” are specific to the site.
Scroll, wait, and detect the end
IJavaScriptExecutor runs JavaScript in the currently selected frame or window, making it suitable for advancing either the window or a nested scroll container. Selenium documents the interface in its .NET API reference.
#1 Best Overall
- Scroll by a bounded amount. Advance by roughly one viewport height so newly exposed content can trigger loading.
- Wait for a meaningful page condition. Prefer a new item appearing, a loading indicator disappearing, or an end marker becoming visible. A fixed sleep alone is fragile because response and rendering times vary.
- Check progress. Track the number of feed items or scroll height before and after each step. Stop when the site exposes an end marker, or after a bounded number of checks without progress.
- Set a maximum. A maximum iteration count or elapsed-time limit prevents an endless loop on sites that never report completion.
Here is a runnable starter for a window-scrolling page. Replace the URL and the example selectors with selectors from the target site. It waits for either the item count to increase or the end marker to appear. If neither happens within the wait period, the loop stops rather than scrolling forever.
using System;
using System.IO;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
class Program
{
static void Main()
{
using IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://example.com/feed");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
const string itemSelector = ".feed-item"; // Replace for the site
const string endSelector = ".end-of-feed"; // Replace, or use a site-specific condition
const int maxSteps = 100;
int stepsWithoutProgress = 0;
const int maxStepsWithoutProgress = 2;
for (int step = 0; step < maxSteps; step++)
{
long beforeHeight = Convert.ToInt64(
((IJavaScriptExecutor)driver).ExecuteScript(
"return document.documentElement.scrollHeight;"));
int beforeItems = driver.FindElements(By.CssSelector(itemSelector)).Count;
((IJavaScriptExecutor)driver).ExecuteScript(
"window.scrollTo(0, document.documentElement.scrollHeight);");
try
{
wait.Until(d =>
{
bool endReached = d.FindElements(By.CssSelector(endSelector)).Count > 0;
long height = Convert.ToInt64(
((IJavaScriptExecutor)d).ExecuteScript(
"return document.documentElement.scrollHeight;"));
int items = d.FindElements(By.CssSelector(itemSelector)).Count;
return endReached || height > beforeHeight || items > beforeItems;
});
}
catch (WebDriverTimeoutException)
{
// No observable change during this wait; count it as a no-progress step.
}
bool atEnd = driver.FindElements(By.CssSelector(endSelector)).Count > 0;
long afterHeight = Convert.ToInt64(
((IJavaScriptExecutor)driver).ExecuteScript(
"return document.documentElement.scrollHeight;"));
int afterItems = driver.FindElements(By.CssSelector(itemSelector)).Count;
bool progressed = afterHeight > beforeHeight || afterItems > beforeItems;
if (atEnd)
break;
stepsWithoutProgress = progressed ? 0 : stepsWithoutProgress + 1;
if (stepsWithoutProgress >= maxStepsWithoutProgress)
break;
}
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile(Path.GetFullPath("feed.png"));
}
}
The example uses Selenium’s explicit wait support and a page-specific end selector. On a site without an end marker, remove that selector check and rely on a reliable item-count or scroll-height condition plus the loop bounds. If a feed deliberately reuses DOM nodes, item count may not grow; choose a condition that reflects actual newly loaded content instead.
Rank #2
- Intuitive interface of a conventional FTP client
- Easy and Reliable FTP Site Maintenance.
- FTP Automation and Synchronization
For a nested scroll container
Change the JavaScript to operate on the element that scrolls. For example, if inspection identifies #feed-panel as the container, obtain its scrollHeight and scrollTop, advance its scrollTop, and measure that same element after waiting. Use the element’s item count or its end marker for progress. Scrolling window will not load more items if the feed panel is the actual scroll target.
For asynchronous page conditions
The .NET interface also exposes ExecuteAsyncScript, which uses a callback-based mechanism for asynchronous scripts. It can be useful when the page condition is naturally represented by JavaScript, but Selenium does not prescribe a universal infinite-scroll script; keep the site-specific load signal and a hard bound.
Rank #3
Save a viewport or build one tall image
Save the current browser view
The sample saves the current browsing context as a PNG. Selenium’s .NET Screenshot API documents SaveAsFile(string); it saves PNG and overwrites an existing file at the same path. A screenshot taken once before the scrolling loop would show only content available at that moment, not items the page has yet to load.
Capture the feed as segments and stitch them
If the deliverable must be one tall PNG, capture viewport-sized segments as you scroll, then combine them with an image-processing library outside WebDriver. Move by slightly less than the viewport height to create overlap; the overlap helps align segments and spot repeated or missing content. Selenium’s reviewed documentation covers screenshots of the current browsing context and elements, but does not promise a universal infinite-page stitching method or consistent handling of arbitrarily tall full-page images.
Rank #4
- Check segment joins for duplicate or missing rows before using the result.
- Sticky headers may appear in every segment; account for them when stitching.
- Lazy-loaded images, animations, ads, and changing feed content can make adjacent captures inconsistent.
- If the target content sits inside one stable DOM element, an element screenshot may be a better fit than stitching the entire page. Selenium documents element screenshots separately in its WebDriver documentation.
Performance, reliability, and output choices
Infinite scroll means the browser must trigger each additional load before that content exists to capture. A single screenshot call cannot substitute for that sequence. Reliability depends more on targeting the right scroll surface and waiting for observable page behavior than on adding a longer fixed delay.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Choose output based on the job: a viewport PNG is the simplest and most predictable; element capture limits the image to a stable page region; a stitched image covers loaded feed content but adds capture time and seam review. Selenium’s broader WebDriver examples also include printing to PDF, but that produces a document rather than the image requested here.
Best Value
Troubleshooting common failures
- The screenshot contains only the first screen: the page was captured before scrolling triggered more loads, or the loop scrolled the wrong target. Verify the scroll container and take the screenshot only after the loading loop.
- The loop stops before the feed ends: the item selector or end condition may not match the site. Inspect the rendered DOM and choose a condition tied to new items or the actual end marker.
- The loop never ends: the site may not expose an end marker, or height may keep changing for unrelated reasons. Require stable content across bounded checks and retain a maximum iteration or time limit.
- The page appears unchanged after a scroll: content may load after a delay or only after scrolling a nested panel. Wait on a specific loading or content condition, and verify the correct element’s
scrollTopchanges. - The stitched image has repeated or missing rows: inspect overlap and adjust segment advance; also check for sticky elements, lazy images, or content changing during capture.
- The output file replaces an earlier screenshot:
SaveAsFileoverwrites the file at the destination path. Use a unique filename when retaining multiple runs. - WebDriver fails to start or navigate: confirm the installed Selenium package, browser, and driver are compatible, and consult the current Selenium downloads listing.
Or skip the browser setup
If the goal is a clean screenshot rather than automating an infinite feed interaction, ScreenshotNeo can return an image or PDF with one GET request. Its API captures a URL; it does not replace a Selenium scroll loop for content that only appears after repeated user scrolling.
Example using the documented ScreenshotNeo API:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Recommended Free Tools
Frequently Asked Questions
Can Selenium capture an infinite-scroll page with one screenshot call?
No. The page must first load the content by scrolling; a single call captures only the content available at capture time.
Does the C# example guarantee a complete capture of every infinite feed?
No. The item selector, scroll target, and end condition must match the site, and the loop bounds intentionally prevent unending automation.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




