October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Capture Selenium Screenshots in Docker with Headless Chrome

Use Python Selenium's save_screenshot() with headless Chrome in a version-pinned Docker container. Learn remote setup, sizing, shared memory, and fixes for common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Python, capture the current browser view with driver.save_screenshot("screenshot.png"). Run Chrome in headless mode, use a version-pinned Selenium container with enough shared memory, and make sure your CI system collects the file from the process that wrote it.

Capture a screenshot with Selenium

After creating a WebDriver session and navigating to a page, call save_screenshot() with a path writable by the Python test process. The method saves the current browsing context; it is not a general guarantee of a full-page capture. Selenium also provides an element screenshot method when you need an individual element instead.

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=new")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    saved = driver.save_screenshot("screenshot.png")
    if not saved:
        raise RuntimeError("Selenium did not save the screenshot")
finally:
    driver.quit()

Selenium’s Chrome documentation lists --headless=new among commonly used Chrome arguments and documents screenshot methods. Chrome’s headless documentation also shows the argument passed through Selenium Chrome options.

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

Run Chrome in a Selenium Docker container

The official selenium/standalone-chrome image runs a standalone Selenium Grid endpoint. Start it with port 4444 available to the test process and allocate shared memory:

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
docker run --rm -p 4444:4444 --shm-size=2g 
  selenium/standalone-chrome:4.48.0-20260905

This tag is an example from the docker-selenium README, not a claim that it is the latest tag. Select and pin a full image tag suitable for your environment. Selenium recommends starting with --shm-size=2g to help address browser crashes, but says the right allocation depends on workload; tune it rather than treating 2 GB as a universal minimum.

Connect a Python test to the container

When Chrome runs in a separate container, the test process connects to its WebDriver endpoint. The screenshot bytes are returned through WebDriver and the binding writes the requested file path in the test process’s environment.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

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

driver = webdriver.Remote(
    command_executor="http://localhost:4444/wd/hub",
    options=options,
)
try:
    driver.get("https://example.com")
    driver.save_screenshot("artifacts/screenshot.png")
finally:
    driver.quit()

Create the artifacts directory before running this example, and ensure the test process can write to it. In CI, point artifact collection at that process-side path, not at a path inside the browser container. Validate the endpoint path and remote-session behavior against the Selenium version and deployment you actually use.

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

Set versions and capture dimensions deliberately

Selenium’s Chrome documentation says Selenium 4 is compatible with Chrome v75 and later, and that Chrome and ChromeDriver must match at the major-version level. Pin a full Selenium image tag so the browser and Grid versions are explicit; check the tag’s contents when upgrading rather than relying on an unpinned image name.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

For repeatable output, set the browser window size before navigation or capture, and keep it consistent across runs:

driver.set_window_size(1280, 900)
driver.get("https://example.com")
driver.save_screenshot("screenshot.png")

A viewport screenshot and a full-page screenshot are different requirements. Selenium’s cited examples establish current-context and element screenshots, not universal full-page behavior. Confirm the capture semantics of the method you choose if the whole document must fit in one image.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Choose between WebDriver and Chrome’s headless CLI

Method Best fit Capture and output considerations
Selenium WebDriver The page must be opened or interacted with through a WebDriver session. Use driver.save_screenshot(path) for the current browsing context, or an element screenshot method for one element. The test process writes the result at the specified path.
Chrome headless CLI The job only needs a browser command and does not need WebDriver interaction. Chrome documents --screenshot with an explicit --window-size; this is a separate workflow and should not be assumed to behave identically to WebDriver.

For example, Chrome documents this command-line form:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless=new --screenshot --window-size=412,892 https://developer.chrome.com/

See Chrome’s headless documentation for the CLI workflow and options.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot container screenshots

  • Chrome exits or crashes: inspect the container’s /dev/shm allocation. Selenium recommends --shm-size=2g as a starting workaround; adjust it to the workload.
  • The session will not start because of a version mismatch: compare Chrome and ChromeDriver major versions, then verify the full Selenium image tag and packaged browser version.
  • Headless startup fails after an Xvfb change: consult the docker-selenium README for the exact image tag. Its version-sensitive guidance says newer Chrome/Chromium versions require SE_START_XVFB=true for --headless=new at v127+, and for --headless at v132+. Confirm the guidance for your image instead of assuming headless and Xvfb settings are independent.
  • The screenshot is missing from CI artifacts: identify where the test process runs, check that the target directory exists and is writable, and configure the artifact collector to use that process-side path.
  • The image has the wrong size or composition: set and record the viewport or window size, and check whether you need an element, viewport, or full-page capture.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return a screenshot or PDF without running a browser container yourself. For example, save a WebP response with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://example.com 
  -o shot.webp

See the ScreenshotNeo documentation for request options and response details. Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot; each cleanup step can be disabled. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

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

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.

Leave a Reply

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

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.