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 desk6 min

How to Capture Selenium Screenshots in GitHub Actions with Headless Chrome

Save Selenium screenshots from headless Chrome in GitHub Actions and upload them as artifacts, including when tests fail.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium’s Chrome driver with Chrome’s --headless option, save the current browser window to a PNG in your workspace, then upload that directory as a GitHub Actions artifact. The workflow below also uploads screenshots when a test fails, so you can inspect them after the job ends.

What the workflow does

A hosted runner has no visible desktop to interact with, but Chrome can run in headless mode. Selenium can capture the current browser window to a file; GitHub Actions artifacts preserve that file after the job finishes.

  1. Install the project’s Selenium and test dependencies.
  2. Start Chrome with --headless, set a deliberate viewport, and wait for the page state you need.
  3. Save the screenshot under a known directory such as artifacts/.
  4. Upload that directory with actions/upload-artifact, configured to run even if the test step fails.
  5. Close the WebDriver in a finally block so the browser is shut down on errors as well as success.

Capture a screenshot with Selenium in Python

This runnable example writes the current browser window to artifacts/page.png. The 1440×1000 viewport is an example choice, not a GitHub Actions or Selenium requirement.

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

output = Path("artifacts")
output.mkdir(parents=True, exist_ok=True)

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

driver = webdriver.Chrome(options=options)
try:
    driver.set_window_size(1440, 1000)
    driver.get("https://example.com")
    saved = driver.save_screenshot(str(output / "page.png"))
    if not saved:
        raise OSError("Selenium could not write the screenshot")
finally:
    driver.quit()

Selenium’s TakeScreenshot documentation describes this as capturing the current browsing context. In Python, save_screenshot(path) writes a PNG and returns False if an I/O error prevents writing, so checking the return value can make a missing file fail the test clearly.

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

Wait for the state you intend to capture

A successful screenshot call does not mean the application has finished rendering. If the page loads data asynchronously, wait for a stable signal—typically a target element becoming visible—before calling save_screenshot. Keep that wait tied to the application state your test is meant to verify rather than adding an arbitrary delay by default.

Choose the capture target deliberately

The basic call captures the current browser window, not necessarily the entire height of a long page. Selenium also supports capturing a particular element; use that when the evidence should focus on one component, and choose a selector stable enough to survive ordinary page changes. Set the window size before navigation when consistent viewport dimensions matter. See Selenium’s screenshot guide for binding-specific examples.

Upload screenshots from GitHub Actions

Put the test step before the artifact upload step and use the same directory in both places. The if: always() condition lets the upload step run after a failing test step, which is useful when failure hooks create diagnostic screenshots. It cannot upload a file that was never created.

name: Selenium tests

on:
  push:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: "3.x"

      - name: Install dependencies
        run: python -m pip install selenium

      - name: Run Selenium test
        run: python test_screenshot.py

      - name: Upload screenshots
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: selenium-screenshots
          path: artifacts/

This example pins action major versions as shown; check the actions’ current official documentation and your repository’s policy before adopting or changing versions. GitHub describes artifacts as a way to retain and share files produced by a workflow, and lists screenshots among common artifacts: Workflow artifacts.

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

Capture on test failure

If screenshots are only useful for diagnosing failures, put the screenshot call in your test framework’s failure hook or teardown and still upload artifacts/ with if: always(). Ensure the directory exists before saving. A screenshot taken during teardown can only show the state Selenium still has access to; if setup failed before Chrome started or the target page loaded, there may be no meaningful image to preserve.

Runner and browser version considerations

GitHub-hosted runner images include browser automation software, but installed versions change as the images are updated. The Ubuntu 24.04 runner image README’s inventory reviewed on 2026-10-03 listed Google Chrome 153.0.8010.52, ChromeDriver 153.0.8010.52, Chromium 153.0.8010.0, and Selenium server 4.49.0. Treat these as an inventory snapshot, not a promise about later runs: see the Ubuntu 24.04 runner image README.

The runner-images project currently identifies ubuntu-latest as an alias for Ubuntu 24.04 and notes that the -latest label follows the latest generally available image over time. Select an explicit OS label when that fits your reproducibility needs, and inspect the job setup log to see the image and installed software actually used. Consult the GitHub Actions Runner Images project for current labels and image details.

Selenium bindings use Selenium Manager by default for automated browser and driver management. On a hosted runner that already has browser and driver binaries, diagnose the versions and paths resolved in the actual job rather than assuming that installation or PATH behavior matches another image. Selenium’s Selenium Manager documentation explains its role.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and fixes

Symptom Likely cause What to check or change
No screenshot appears in the artifact The test failed before writing the file, the output directory was missing, or the upload path does not match the code. Create the directory before capture, check the screenshot method’s return value, and use the same path in the test and artifact step. Confirm the upload step ran.
The upload step reports that no files were found The configured artifact path is wrong or no image was produced. Check the test’s output path and runner logs. Remember that if: always() runs the upload step; it does not create missing files.
Chrome or ChromeDriver fails to start The resolved browser and driver are unavailable or mismatched, or startup configuration differs from expectations. Inspect the runner setup log for the selected image and actual browser/driver versions and paths. Check whether the runner provides binaries and how Selenium Manager resolves them.
The PNG shows a loading state or incomplete page The screenshot was taken before the application reached the intended state. Wait for a specific element or other meaningful readiness condition before capture.
The image dimensions vary between runs The browser window size was not set consistently before capture. Set a deliberate window size before navigation, then keep the value consistent across test runs.
The screenshot omits content below the visible window The basic WebDriver screenshot captures the current window, not a guaranteed full-page image. Decide whether the test needs visible-window evidence or a specific element screenshot; do not assume the basic call captures the whole document.

Reliability, performance, and artifact safety

  • Use a clear readiness condition before capture; an immediate screenshot may be fast but misleading when the page is still rendering.
  • Always close the driver, including when navigation or capture raises an exception.
  • Keep screenshots in a predictable workspace path and upload only the files needed for debugging. GitHub-hosted runners are temporary environments, so a local file alone is not a durable record after the job ends.
  • Screenshots can expose account details, customer data, tokens rendered on the page, or other sensitive information. Review the page content and artifact access policy before uploading them.
  • For repeatable CI behavior, record the selected runner image and resolved browser/driver versions in logs, and revisit the OS label as GitHub updates supported images.

Or skip the browser setup

If you need a screenshot of a public page rather than a Selenium-driven test, ScreenshotNeo offers a one-request screenshot API. It accepts one GET request for a URL and returns PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for request options.

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 and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. 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 screenshots.

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

Frequently Asked Questions

Does Selenium’s basic screenshot call capture a full webpage?

No. The standard WebDriver call captures the current browser window; it does not promise a full-page image.

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.

Can I keep screenshots if a GitHub Actions test fails?

Yes, if the test writes the files and the later artifact upload step is configured to run after failure.

Will every Ubuntu runner use the same Chrome and ChromeDriver versions?

No. Hosted runner software changes with image updates, so check the setup log for the versions used by a particular run.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.