Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Selenium’s ITakesScreenshot interface on the remote driver, then save the returned screenshot to a path on the machine running your C# test. A Grid session does not change the capture call: the browser is remote, but the screenshot is returned to the client through WebDriver. Create the artifact directory first, and use a unique filename so parallel tests do not overwrite one another.
Capture a screenshot from a remote Grid session
For a standard screenshot of the browser’s current view, call GetScreenshot() on the driver and save the result with SaveAsFile. RemoteWebDriver supports ITakesScreenshot, so the same basic API works when the browser is running on a Grid node rather than on the test machine.
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
// driver is a RemoteWebDriver connected to Selenium Grid.
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile("artifacts/screenshot.png");
The example assumes driver is already connected and the artifacts directory exists. The API writes PNG output; if the destination file already exists, it is overwritten. In a test suite, it is usually safer to prepare the directory and construct a distinct path for each capture, as shown below.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsWhat happens across the Grid boundary
Selenium Grid routes WebDriver commands from the client to a remote browser. The browser and its filesystem are on the remote machine; the C# process issues the screenshot command, receives the screenshot, and saves it through the .NET API. Consequently, a path passed to SaveAsFile should be accessible to the test process. It is not automatically a path on the Grid node.
#1 Best Overall
This distinction matters when tests run in CI, containers, or parallel workers. Choose a client-side artifact directory that the test runner can retain or publish. If you instead need a file created directly on a remote node, that is a separate node-side artifact workflow; the regular screenshot-and-save call does not make the local path resolve remotely.
Save unique artifacts in a test
For failure diagnostics, capture before quitting the driver and name the file with information that distinguishes the test or browser session. The following method creates the output directory and adds a UTC timestamp and a GUID to avoid collisions when tests run concurrently.
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.IO;
static string SaveScreenshot(RemoteWebDriver driver, string testName)
{
var artifactDirectory = Path.GetFullPath("artifacts");
Directory.CreateDirectory(artifactDirectory);
var safeTestName = string.Concat(testName.Split(Path.GetInvalidFileNameChars()));
var fileName = $"{safeTestName}-{DateTime.UtcNow:yyyyMMdd-HHmmssfff}-{Guid.NewGuid():N}.png";
var path = Path.Combine(artifactDirectory, fileName);
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile(path);
return path;
}
Call it while the session is still active, for example in a test framework’s failure hook or cleanup path that runs before driver.Quit(). The returned path can then be passed to the framework’s attachment or artifact-publishing mechanism. Selenium’s screenshot API gives you the image file; it does not itself configure your CI system to retain or display it.
Rank #2
For code that accepts IWebDriver rather than RemoteWebDriver, the same explicit cast works when the active implementation supports ITakesScreenshot. If the cast fails, the current driver implementation or configuration does not expose the interface as expected; check the browser/driver combination and Selenium binding version instead of assuming every custom wrapper forwards it.
Capture an element rather than the browser view
When the useful evidence is a particular control, card, or error message, Selenium’s C# example uses screenshot support on the IWebElement. Locate the element, cast it to ITakesScreenshot, and save the result.
IWebElement resultPanel = driver.FindElement(By.CssSelector(".result-panel"));
var elementScreenshot = ((ITakesScreenshot)resultPanel).GetScreenshot();
elementScreenshot.SaveAsFile("artifacts/result-panel.png");
This captures the element rather than asking for a full-page image. Element screenshot support can depend on the selected browser and driver, particularly on older or unusual Grid deployments, so verify it against the browsers you actually run. Use a unique output path here too: saving to the same filename again overwrites the previous file.
Rank #3
Viewport screenshots are not automatically full-page screenshots
The standard cross-language Selenium screenshot operation captures the current browser view. Do not treat it as a portable instruction to capture every scrollable portion of a long page. Selenium documents browser-specific functionality separately, including a Firefox-specific custom command example for full-page capture. That is not evidence of one universal full-page C# operation across every Grid browser.
If full-page output is a requirement, confirm the exact browser, Selenium binding version, and remote node support for the relevant browser-specific capability or command. A command that works for one browser should not be assumed to work for another. If the requirement is simply a conventional diagnostic screenshot, the standard WebDriver call avoids that browser-specific dependency.
Choose the capture method by the artifact you need
| Need | Method | Important distinction |
|---|---|---|
| Current browser view | ITakesScreenshot on the driver |
Standard WebDriver screenshot pattern; save the returned image on the client. |
| One visible element | ITakesScreenshot on the IWebElement |
Element support should be verified for the selected browser and Grid setup. |
| Entire long page | Browser-specific capability or command, if supported | Do not assume a universal full-page method for all C# Grid browsers. |
| Screenshot saved by the test client | SaveAsFile(clientPath) |
The path belongs to the machine running the C# process, not inherently the remote node. |
Troubleshoot common screenshot problems
The screenshot call throws or the cast fails
Check that the active driver or element supports ITakesScreenshot, and that you are using the expected browser/driver implementation and Selenium binding version. With a custom driver wrapper, confirm that it exposes or forwards the screenshot interface. For an element capture, first verify that the element was located and that element screenshot support is available in the target browser.
Rank #4
The file is missing after the test
Check the path from the perspective of the test process, not the Grid node. Ensure the destination directory exists, that the test account can write there, and that your test runner publishes or retains that directory. SaveAsFile writes the image; it does not move it to a CI artifact store.
A later screenshot replaced an earlier one
The documented save behavior overwrites an existing destination. Add a test name, session identifier, timestamp, or other unique component to each filename, and consider how parallel workers share the artifact directory.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The image shows only part of a long page
The standard screenshot captures the current browser view, not a guaranteed full-page image. Use a documented browser-specific approach only after confirming it for the actual remote browser and Selenium version. Otherwise, capture the relevant viewport or element.
Best Value
Saving works locally but not in Grid
Do not use a node-side path when calling the client-side SaveAsFile method. The screenshot is returned to the client and the supplied path is resolved by the C# test process. If a node-side file is specifically required, configure a separate mechanism for that purpose.
Screenshot cleanup hides the original test failure
Keep failure reporting resilient: record a screenshot-capture error separately rather than allowing a secondary artifact exception to replace the assertion or browser error that caused the test to fail. Capture before closing the session, and preserve both the original failure and any diagnostic-capture failure in the test report.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and artifact handling
A remote screenshot involves a WebDriver command to the browser and delivery of the resulting image to the client before the client writes it to disk. In practice, the request depends on the live Grid session, the remote browser, and the connection between node and client. Reserve capture for useful checkpoints—often failures or selected milestones—rather than assuming it is a zero-cost operation in every test step.
- Capture at the right time: take the image while the page state and session still exist, before quitting the driver.
- Keep artifacts attributable: use distinct filenames and retain the test name or other identifier in the test report.
- Plan retention: direct output to a directory your runner can collect, and apply the retention policy used for test artifacts.
- Protect contents: screenshots can show rendered page content, so handle them under the same access and retention controls as other test evidence.
- Separate primary and diagnostic failures: preserve the original test result even if screenshot capture or file writing also fails.
Or skip the browser setup
If you need an image of a public URL rather than the exact state of an already-running Selenium session, ScreenshotNeo offers a URL-based screenshot API and an MCP server for AI clients. It is not a replacement for capturing the live Grid session or its authenticated, test-specific state. One GET request returns an image; the API documentation is at ScreenshotNeo docs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
With ScreenshotNeo, cookie and consent banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Learn more at ScreenshotNeo.
Sign up for the free plan and get 1,000 screenshots a month with no card.
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.
Recommended Free Tools

