ScreenshotNeo

BlogHow-to

How to Take Screenshots of Web Pages with Selenium and ChromeDriver on macOS

Use Python and Selenium to capture a web page or element as a PNG on macOS. Set up Chrome, handle headless mode, and understand full-page limits.

By the ScreenshotNeo team4 October 20265 min read

On macOS, the simplest way to save a webpage screenshot with Selenium is to install the Selenium Python package, launch Chrome through webdriver.Chrome(), navigate to a URL, and call driver.save_screenshot("page.png"). Modern Selenium can use Selenium Manager to handle browser driver setup on most supported configurations, so a separate ChromeDriver download is often unnecessary.

1. Install Selenium and prepare Chrome

Make sure Google Chrome is installed. Then create and activate a virtual environment if you use one, and install or update Selenium:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U selenium

The current Selenium Python documentation describes Selenium Manager as handling browser and driver installation for most supported platforms and browsers when a WebDriver is instantiated. Manual browser or driver installation is still an option. See the Selenium Python documentation.

Selenium’s Chrome guidance says Selenium 4 is compatible with Chrome 75 and later, and that Chrome and ChromeDriver major versions should match. Treat this as the guidance in the current documentation, not a guarantee for every future release. See Chrome-specific WebDriver functionality.

2. Capture the current browser view as a PNG

This complete script opens a page, saves a PNG of the current browsing context, and closes Chrome even if navigation or saving raises an error:

from selenium import webdriver


driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    driver.save_screenshot("page.png")
finally:
    driver.quit()

Run it from the terminal with python screenshot.py, assuming you saved the code in screenshot.py. The file is written relative to the directory from which you ran the command. Use an absolute path if you want to choose its location explicitly, for example "/Users/you/Desktop/page.png".

save_screenshot(filename) saves a PNG screenshot of the current window; use a filename ending in .png. The WebDriver screenshot endpoint returns image data encoded in Base64, as described by the Selenium Project documentation.

3. Capture one element instead of the page view

When you only need a particular element, locate it and call its screenshot method. This example saves the first matching h1:

from selenium import webdriver
from selenium.webdriver.common.by import By


driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    heading = driver.find_element(By.CSS_SELECTOR, "h1")
    heading.screenshot("heading.png")
finally:
    driver.quit()

Replace h1 with a selector for the target element. If the selector matches nothing, Selenium raises an error instead of saving an element image. Selenium documents element capture with element.screenshot("element.png") in its window and tab examples.

4. Run Chrome in headless mode

Headless mode runs Chrome without displaying a normal browser window. Pass Chrome options when creating the driver:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://www.example.com")
    driver.save_screenshot("page.png")
finally:
    driver.quit()

The Selenium Chrome documentation lists --headless=new among commonly used Chrome arguments and shows passing ChromeOptions to the driver. The cited guidance does not specify a special macOS-only screenshot switch.

5. Know what the screenshot includes

Call Capture scope Use it for
driver.save_screenshot("page.png") The current browser window or browsing context A screenshot of the view Chrome currently presents
element.screenshot("element.png") The selected element A focused image of one component or region

Do not assume the standard driver screenshot call captures the whole scrollable document. The cited Selenium material describes a current-window screenshot and an element screenshot; it does not establish built-in full-page capture. If the page is taller than the visible browser area, the standard call should be treated as a browser-view capture, not a guaranteed full-page image.

6. Troubleshoot common problems

Symptom Likely cause What to do
Chrome does not start Chrome is missing, or Selenium could not resolve a compatible browser and driver for the environment. Confirm Chrome is installed and update Selenium. Selenium Manager handles setup in most supported configurations; consult the Selenium Python documentation if you need to manage the browser or driver manually.
A driver or session creation error mentions compatibility The Chrome and ChromeDriver major versions do not agree. Check both versions and align their major versions, following the current Selenium Chrome guidance.
The screenshot file is missing The script failed before the save call, or the output path is not the directory you expected. Read the traceback, confirm navigation completed, and use an absolute output path to remove ambiguity.
The page image looks incomplete The screenshot reflects the current browser view; the page may extend below the visible area or content may not yet be present. Confirm the intended capture scope and that the page has loaded the content you need before saving. The cited API material does not promise a full-page capture.
Element capture fails The CSS selector did not find an element in the current page state. Check the selector and page URL, then locate the element after navigating to the page.

The documentation cited here does not establish different setup fixes for Apple Silicon and Intel Macs. Avoid applying architecture-specific driver advice without evidence for the actual error and environment.

7. Reliability, runtime, and cost considerations

  • Close the browser reliably: put driver.quit() in a finally block so it runs when capture raises an exception.
  • Make setup repeatable: pin or record your Selenium package version when reproducibility matters, and keep Chrome and ChromeDriver major versions aligned when managing them yourself.
  • Expect browser work: Selenium starts a browser process and loads the target page. The supplied documentation provides no benchmark for capture time or resource use, so measure your own pages and environment.
  • Budget for infrastructure: a Selenium workflow requires a machine or service where Python and Chrome can run. The research provides no prices or cost comparison for hosting that browser.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns an image or PDF, so a script does not need to install and launch Chrome itself. 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 removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots per month, with no card required.

FAQ

Does Selenium save a PNG or a Base64 string?

The Python save_screenshot method writes a PNG file. At the WebDriver protocol level, the screenshot endpoint returns Base64-encoded image data.

Do I need to download ChromeDriver separately on macOS?

Usually not with a modern Selenium setup: Selenium Manager handles browser and driver setup for most supported configurations. Manual installation remains possible, and Chrome and ChromeDriver major versions should match when using ChromeDriver.

Can I use the same code in headless Chrome?

Yes. Create ChromeOptions, add --headless=new, and pass the options to webdriver.Chrome(options=options).

Does this workflow create a PDF?

No. The examples here save PNG screenshots. ScreenshotNeo’s API also supports PDF output, including paper size, margins, landscape orientation, and page ranges.