Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 PC×
Skip to content
Chrome

How to Take Screenshots in Dark Mode with Selenium

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.

To capture a site’s own dark theme with Selenium in Chrome, emulate the CSS prefers-color-scheme: dark preference through Chrome DevTools Protocol (CDP), then load the page and save a screenshot. Selenium’s screenshot method captures what the browser rendered; it does not turn dark mode on by itself.

Enable the site’s dark theme in Chrome

Many sites choose their colors based on the CSS prefers-color-scheme media feature. Chrome can emulate that preference using CDP’s Emulation.setEmulatedMedia command. Set the preference before navigation so the page sees it as it loads. If you change the preference after a page is open, reload the page so it can respond.

Here is a complete Python example using Selenium’s Chrome driver. Replace the example URL with a page that supports a dark theme based on the color-scheme preference.

from selenium import webdriver

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)

try:
    driver.execute_cdp_cmd(
        "Emulation.setEmulatedMedia",
        {"features": [{"name": "prefers-color-scheme", "value": "dark"}]},
    )
    driver.get("https://example.com")
    driver.save_screenshot("dark-mode.png")
finally:
    driver.quit()

The CDP command and its parameter names are specific: the method is Emulation.setEmulatedMedia, and the feature is named prefers-color-scheme with the value dark. The finally block closes the browser even if navigation or capture raises an error.

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

Make sure the target page supports this preference

Emulation changes the browser preference exposed to the page; it cannot add a dark theme to a site that has none. If the site uses a manual theme switch, a saved account setting, or another mechanism instead of prefers-color-scheme, this command alone may not select its dark appearance. Choose a page whose dark styling is activated by the CSS media feature when testing this workflow.

Verify the theme, not just the image file

A successful call to save_screenshot shows that Selenium wrote an image. It does not prove the page rendered the intended theme. Before using a screenshot as a visual-regression fixture, verify a known visual indicator or inspect a relevant computed style. You can also compare a known page region against an expected dark rendering.

Keep the check tied to the site under test: the browser can report a dark color-scheme preference while the page still renders light colors because it does not support that preference, has not finished updating, or uses a different theme control. A screenshot is useful evidence of the rendered result, but it is not itself a theme assertion.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Capture the full page or one element

Selenium provides page screenshot methods and element screenshot methods. Use driver.save_screenshot("dark-mode.png") when the fixture should represent the page view. When the test is about one component, locate that element and use its screenshot API instead:

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.
element = driver.find_element("css selector", ".product-card")
element.screenshot("product-card-dark.png")

Replace .product-card with a selector that identifies the element on your page. A focused element capture is useful when unrelated page content would make a component comparison noisy. The element still needs to be rendered in the intended theme before you capture it.

Site dark theme versus Chrome automatic dark rendering

There are two different behaviors that are easy to confuse:

  • Site theme via preference: Emulate prefers-color-scheme: dark. This tests whether the site’s own supported dark styling responds to the user preference.
  • Browser automatic dark rendering: Chrome’s Emulation.setAutoDarkModeOverride causes web content to be rendered using an automatic dark theme. This tests Chrome’s browser-side transformation, not necessarily a site-authored dark theme.

Choose the method that matches the behavior you need to test. For a site’s built-in dark theme, use the media-feature override in the Python example. Use automatic dark rendering only when the browser transformation itself is the subject of the test; otherwise, it changes the test condition.

Compatibility and stability

Selenium’s CDP integration is Chromium-specific and depends on the browser version. Selenium’s Chrome DevTools documentation warns that CDP was not designed as a stable testing API and that functionality is highly dependent on browser version. Selenium describes CDP access as a temporary bridge while WebDriver BiDi support is implemented.

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

WebDriver BiDi is Selenium’s standards-based, cross-browser direction for browser control. The documentation considered here does not establish an equivalent BiDi command for this particular media emulation, so do not assume you can replace the CDP call with a portable BiDi command today. Check current Selenium and browser support before changing the implementation.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Troubleshoot a screenshot that still looks light

The emulation command ran after navigation

If you set the preference after opening the page, reload it. A page may evaluate its theme during loading and not react to a later preference change automatically.

The site does not use prefers-color-scheme

The CDP setting exposes a browser preference; it does not force every site to provide a dark palette. Confirm that the page implements dark styling for the media feature. If it relies on a manual switch or account setting, test that mechanism separately.

You expected Chrome to force-darken the page

prefers-color-scheme asks the site to use its own supported dark theme. It is not the same as Chrome’s automatic dark rendering. Use the latter only if browser-generated dark rendering is what you intend to validate.

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

The CDP call fails or behaves differently after an upgrade

CDP behavior depends on the installed browser version, and Selenium characterizes the API as unstable for testing. Check the Selenium and Chrome versions in the environment and whether the current Selenium binding supports the relevant CDP command. Avoid assuming that a script that worked with one browser version will behave identically with another.

The output exists, but it is not a valid dark-mode fixture

Separate capture success from theme success. Inspect the page’s known theme indicator, a computed style relevant to the test, or a known region in the image before accepting the fixture. If the site is still loading or the expected dark appearance has not settled, investigate that page state rather than treating the screenshot file as proof of the desired result.

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

Performance, reliability, and cost considerations

The Selenium workflow controls a real browser session, so the page load and rendering determine when a useful image is available. Applying emulation before navigation avoids needing an extra reload solely to apply the preference. For repeatable visual tests, keep the target page and the theme condition consistent, and verify the rendered theme as part of test setup rather than relying only on the screenshot call.

The sources for this procedure do not establish a capture-time benchmark or a universal cost for running Selenium; those depend on the browser environment and how it is hosted. The meaningful compatibility caveat is the version sensitivity of CDP, not a fixed performance number.

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

Or skip the browser setup

If you need an API rather than a Selenium-managed browser, ScreenshotNeo is a website screenshot API and MCP server for developers. It has a dark-mode option; see the API documentation for its supported request parameters. The example below uses the documented one-request capture form and does not assume a dark-mode parameter name.

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

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free, and every feature is available on every plan. Sign up free for 1,000 screenshots a month, with no card required.

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 *

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

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
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.