October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Take a Screenshot in Headless Chrome with Selenium Grid

Use a headless Chrome WebDriver session on Selenium Grid, wait for the page state you need, and save the screenshot as a PNG or retrieve its bytes on the test runner.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start a headless Chrome session through Selenium Grid, navigate to the page, wait for the content you need, then call Selenium’s screenshot method on that WebDriver session. In Python, driver.save_screenshot("page.png") writes a PNG; when the test runner needs the image, you can instead retrieve PNG bytes and write them locally.

Take a screenshot through a Selenium Grid session

This Python example shows the core workflow. Replace GRID_HOST with the Grid endpoint your deployment exposes. The endpoint, authentication, browser capabilities and constructor details can vary by Grid version and setup.

As an Amazon Associate I earn from qualifying purchases.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")

driver = webdriver.Remote(
    command_executor="http://GRID_HOST:4444",
    options=options,
)
try:
    driver.get("https://example.com")
    # Wait for the specific page state your capture requires.
    saved = driver.save_screenshot("page.png")
    if not saved:
        raise OSError("Selenium could not save page.png")
finally:
    driver.quit()

Selenium’s screenshot operation captures the current browsing context. It is not a guarantee of a vertically stitched, full-page image; confirm behavior for the browser and driver version you run. Selenium WebDriver window interactions document the screenshot operation, and the Python WebDriver API documents the Python methods.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose where the screenshot data should go

Save a PNG file

driver.save_screenshot(path) and driver.get_screenshot_as_file(path) save a PNG using the path supplied. The Python API recommends a full path where appropriate and returns False if an I/O error prevents saving. Check that return value and use a writable destination.

Write returned PNG bytes on the test runner

When the browser runs on a separate Grid node, saving to a path may not put the file on the machine running the test. To persist the image on the client, retrieve bytes and write them there:

png = driver.get_screenshot_as_png()
with open("page.png", "wb") as image_file:
    image_file.write(png)

Return base64 for transport

If another component expects encoded data rather than a file, use driver.get_screenshot_as_base64(). Decode it on the receiving side before treating it as PNG image data. The Python API documents all three forms: file, PNG bytes and base64.

The precise Grid remote-file transfer behavior depends on the Grid version and deployment configuration. If you need a file from the browser node, check the official documentation for the version in use rather than assuming a local path is automatically transferred.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for the page state you intend to capture

The screenshot represents the page at the instant Selenium requests it. A successful navigation call alone does not necessarily mean that images, client-rendered content, or other asynchronous elements you care about are ready. Wait for a meaningful condition, such as the target element becoming visible:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# After driver.get(...):
WebDriverWait(driver, 20).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)
driver.save_screenshot("page.png")

Choose a selector or other condition that matches the content under test. A fixed sleep can be too short on a slow run and unnecessarily long on a fast one; it is not a general substitute for waiting on the intended state.

Configure Chrome headless on the Grid node

Chrome’s current Selenium example enables headless mode with the --headless argument. The browser actually launched by Grid runs on a node, so verify its Chrome version and image when investigating differences between local and remote captures. Chrome says modern headless and headful modes use unified Chrome code; since Chrome 132.0.6793.0, the old Headless implementation is available only as the separate chrome-headless-shell binary. See Chrome for Developers’ headless documentation.

Common failures and fixes

  • The screenshot file is missing on the test runner: the save path may refer to the remote browser environment. Use get_screenshot_as_png() and write the bytes in the test process, or follow the remote-file instructions for your specific Grid version.
  • The file exists but is empty or the save returns false: check that the destination directory exists and is writable, and inspect the method’s return value before treating the capture as successful.
  • The page image is blank or missing dynamic content: wait for the particular element or rendering condition required by the test before capturing. Check whether the application itself has completed loading the content.
  • Local and Grid captures differ: compare the Chrome version and browser image on the Grid node with the local environment. Headless configuration is applied to the browser launched remotely, not a local Chrome process.
  • You expected the entire vertical page: the ordinary WebDriver screenshot is documented as a capture of the current browsing context/window. Do not assume it stitches the full document; validate the exact browser and driver behavior or use a capture method that explicitly supports full-page output.
  • You tried Chrome’s --screenshot flag: that is a standalone Chrome command-line workflow, not a screenshot request issued through a Selenium Grid WebDriver session.

Or skip the browser setup

ScreenshotNeo is a screenshot API: a GET request with a URL returns an image or PDF. Its clean-shot workflow accepts cookie/consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, with response headers indicating the page verdict and billing result. It also offers an MCP server with screenshot tools for AI agents. See ScreenshotNeo and the API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

There are 1,000 screenshots per month on the free plan with no card required; paid plans start at $5 for 3,000. Sign up for free.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does Selenium Grid return a screenshot as PNG or base64?

The Python WebDriver API offers PNG file saving, PNG bytes and base64 data. Choose the form that fits how your test runner consumes the image.

Can the normal WebDriver screenshot capture the full page?

The documented operation captures the current browsing context/window; full-page stitching is not established for every Grid, browser and driver combination. Verify your exact deployment.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.