Use Selenium’s screenshot API after the page reaches the state you want to capture. In a remote Selenium setup, the key is where you save the image: a path used by the browser-side session is not automatically a path on your test runner. For most Kubernetes workflows, return the screenshot bytes through WebDriver and write them from the test process to your CI artifacts or storage.
Return a screenshot from a remote Selenium session
This Python example connects to a remote WebDriver, captures the current browser window as PNG bytes, and writes the image on the machine or container running the test. Replace the Grid URL and target URL with values for your deployment.
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
driver = webdriver.Remote(
command_executor="http://selenium-grid.example:4444",
options=options,
)
try:
driver.get("https://example.com")
png = driver.get_screenshot_as_png()
output = Path("artifacts/page.png")
output.parent.mkdir(parents=True, exist_ok=True)
output.write_bytes(png)
finally:
driver.quit()
get_screenshot_as_png() returns image bytes. The file is written by Python in the test process, so the output directory must exist or be created, and that process must have permission to write there. This uses Selenium’s documented interfaces; it is not a claim that the example was executed. The executor address and artifact destination are deployment-specific. See the Selenium Python Chromium WebDriver API, Chrome headless documentation, and ChromeDriver guide.
Save directly to a file when the test and browser process share a filesystem
For a local browser process in the same container as the test, use driver.save_screenshot('/absolute/path/page.png') or driver.get_screenshot_as_file('/absolute/path/page.png'). Use an absolute path ending in .png, make sure its parent directory exists and is writable, and check the method’s Boolean return value: it is false if an I/O error occurs. See the Selenium Python Chromium WebDriver API.
Recommended Free Tools
#1 Best Overall
Choose what to capture
Current browser window
The examples above capture the current window. Do not assume that this means the entire document: the cited Python API describes a current-window screenshot, not a guaranteed full-page capture of content extending below the viewport.
A single element
If you need one chart, table, or component rather than the browser window, Selenium supports element screenshots. Locate the element and use its screenshot method, for example:
Rank #2
chart = driver.find_element("css selector", "#chart")
chart_png = chart.screenshot_as_png
Path("artifacts/chart.png").write_bytes(chart_png)
The screenshot endpoint returns base64-encoded image data, and Selenium’s documentation includes element capture examples. See the Selenium screenshot documentation.
Wait for the right page state
Capture only after the content relevant to your test is ready. For a page that fills in data asynchronously, wait for a meaningful element or condition rather than relying only on navigation completion. There is no universal wait duration: the right signal depends on the page and test. A premature capture can be blank or stale even when the screenshot call succeeds.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWhy can’t I find the screenshot file?
In a remote session, the test client and browser may run in different containers or pods. A file path does not transfer the image between them: it identifies a location in the process’s filesystem context. Selenium’s remote-driver model and screenshot API make the bytes available through WebDriver; writing those bytes in the client process avoids guessing which container owns a path.
Choose a retrieval method based on where the browser runs and how long the artifact must last:
Rank #4
| Method | Use it when | Important limitation |
|---|---|---|
| Return bytes through WebDriver | You need an individual screenshot in the test runner or CI artifact directory. | The client must write or upload the returned bytes. |
| Shared volume | Cooperating containers in the same Kubernetes Pod need to exchange a temporary file. | An emptyDir is removed when the Pod is removed from its node. |
| Persistent volume or object storage | Artifacts must remain available after a Pod is removed or be consumed by later jobs. | Choose and configure storage appropriate to the cluster; no particular provider is required. |
| Selenium Grid session assets | Your deployment uses Grid’s Kubernetes mode and has configured asset handling. | Confirm the Grid version, asset path, and how that deployment retrieves assets; do not assume screenshots are automatically exported. |
Kubernetes documents that emptyDir is shared among containers in the same Pod, survives an individual container crash, and is deleted when the Pod is removed from its node. It is temporary rather than durable storage. Kubernetes also warns that hostPath volumes carry security risks, so they are not a casual substitute for a deliberate artifact-transfer design. See Kubernetes volumes documentation.
Grid Kubernetes asset configuration
The Selenium Grid CLI reference documents --kubernetes-assets-path as the absolute path where session assets will be stored, alongside Kubernetes browser-job settings. Check the documentation for the exact Grid version and the retrieval mechanism exposed by your deployment before building a workflow around it. See the Selenium Grid CLI options.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Troubleshoot screenshot failures
- The test cannot find the file: Determine whether Chrome runs in the test container, a sidecar, or a separate Grid-created Pod. For a remote session, return bytes to the test client or configure shared or durable storage instead of assuming a browser-side path is local.
- The file-writing method reports failure: Use an absolute path with a
.pngextension, create the parent directory, check write permissions, and inspect the method’s Boolean return. - Chrome does not start in the pod: Check that headless mode is configured for the deployment and that the installed Chrome and ChromeDriver versions are compatible. ChromeDriver is a separate executable used to control Chrome; the official guide covers local and remote setup.
- The artifact disappears after the test: Check whether it was saved to an
emptyDirand whether the Pod was removed. That volume’s contents do not persist after Pod removal from the node. - The screenshot is blank or stale: Wait for the page’s relevant content or element before capture. A successful screenshot call does not establish that application data has finished loading.
Or skip the browser setup
If you need a website image rather than a Selenium-driven browser test, ScreenshotNeo provides a screenshot API and MCP server. A single GET request returns an image or PDF; its API documentation is at screenshotneo.com/docs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. AI agents can take screenshots through its MCP server. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Frequently Asked Questions
Does a Selenium screenshot save as PNG?
Yes. Selenium’s Python screenshot methods return PNG data or save a PNG file.
Does an emptyDir survive a container restart?
Kubernetes documents that it survives an individual container crash, but it is deleted when the Pod is removed from its node.
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.

