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.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Call driver.get_screenshot_as_png() to get the current browser window’s screenshot as PNG data in Python. The method returns bytes; to save them yourself, write them to a file opened in binary mode ("wb"). If you only need a PNG file, Selenium’s save_screenshot() method is shorter.

What get_screenshot_as_png() returns

Selenium documents get_screenshot_as_png() as returning a screenshot of the current window “as a binary data.” In Python, the returned value is bytes: image data held in memory, not a filename, a file object, or a base64 string. See the Selenium Python WebDriver API reference.

The method captures the browser’s current window screenshot. It does not itself choose where to save the image, scroll through the page to capture the entire document, or select an individual page element. Those are separate concerns: your code decides what to do with the bytes, and other screenshot methods or browser-specific support may be needed for a different capture scope.

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

Use it when another Python step needs the image data

In-memory PNG bytes are useful when the next step in your program accepts binary data—for example, passing the capture to an image-processing library or uploading it to a service. The method does not require Pillow or another image library merely to capture a screenshot.

Choose a different output form when appropriate

If the goal is to save a PNG and do nothing else with its bytes, call save_screenshot(). If the consumer specifically expects base64 text, call get_screenshot_as_base64(). These methods provide different output forms; base64 is not the same thing as the raw PNG bytes returned by get_screenshot_as_png().

Save the PNG bytes to a file

Assuming driver is an initialized Selenium WebDriver and has already navigated to the page, capture and save the screenshot like this:

png_bytes = driver.get_screenshot_as_png()

with open("screenshot.png", "wb") as image_file:
    image_file.write(png_bytes)

Use "wb", not "w": the screenshot is binary data, so the file must be opened in binary write mode. The with statement closes the file when writing finishes, including if an error occurs. Selenium’s own implementation also writes screenshot data using binary mode; see the Selenium Python WebDriver source.

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

A complete capture-and-save function

This function takes an existing driver, returns the bytes for optional further use, and writes a PNG file. It does not create or navigate the browser session; those steps belong to the caller.

def capture_png(driver, path="screenshot.png"):
    png_bytes = driver.get_screenshot_as_png()

    with open(path, "wb") as image_file:
        image_file.write(png_bytes)

    return png_bytes

Call it after navigation and after any page interactions whose result you want to capture:

png_bytes = capture_png(driver, "output/current-page.png")

The destination directory must already exist, and the running process must have permission to write there. Use an absolute path if you need an unambiguous destination, especially when a scheduled job or test runner may use a different working directory.

Use Selenium’s direct-to-file method for a simpler save

When you do not need the PNG bytes in memory, Selenium can save the screenshot directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
saved = driver.save_screenshot("screenshot.png")
if not saved:
    raise OSError("Selenium could not save the screenshot")

save_screenshot() and get_screenshot_as_file() return True when they save successfully and False if an I/O error occurs, according to the Selenium Python common WebDriver API. Check the boolean if success matters to the rest of your program. Selenium recommends a filename ending in .png; a full path can make the destination clearer.

Method What you get Choose it when
get_screenshot_as_png() PNG image data as Python bytes You need the image in memory for processing, upload, or another Python operation.
save_screenshot(path) A PNG written to a path, plus a success boolean You only need a file on disk.
get_screenshot_as_file(path) A PNG written to a path, plus a success boolean You want Selenium’s direct-to-file alternative.
get_screenshot_as_base64() Base64-encoded screenshot text Your consumer expects base64, such as an HTML embedding workflow.

The API reference documents the base64 method as a base64-encoded screenshot of the current window. Do not write that text to a file as though it were raw PNG bytes; choose the representation expected by the next step in your workflow.

Use the bytes in memory

Keeping the result in a variable lets you process or pass it along without first creating a file. If a downstream library requires a file-like object, wrap the bytes in io.BytesIO:

from io import BytesIO

png_bytes = driver.get_screenshot_as_png()
image_stream = BytesIO(png_bytes)

# Pass image_stream to a library that accepts a binary file-like object.

BytesIO is part of Python’s standard library. It provides a memory-backed stream over the captured bytes; it does not change the screenshot or add Selenium functionality. If a particular library requires a filename or a particular image mode, follow that library’s requirements rather than assuming the stream is interchangeable with a disk file.

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

Pass the raw bytes to an upload or processing step

For an upload API that accepts bytes, pass png_bytes in the form its client library expects. For an image library, supply the bytes or a BytesIO stream if supported. The capture method does not perform image editing, compression choices, resizing, or conversion to another format; those operations belong to a separate tool or step.

Current window, full page, and element screenshots

The documented scope for get_screenshot_as_png() is the current window. A tall document may extend beyond what is visible in that window, so do not assume this method produces a complete, vertically scrolling page capture. Likewise, it does not target a particular element.

Selenium’s quick reference lists adjacent screenshot forms and examples, but full-page behavior depends on the API and browser/driver implementation in use. Confirm support for your specific setup before designing a workflow that depends on a full-document image. See the Selenium Python quick reference.

  • For the current window, use get_screenshot_as_png() when you want bytes, or a direct-save method when you want a file.
  • For one element, use an element screenshot method supported by your Selenium/browser setup.
  • For a full document, verify that the chosen API and browser/driver support the behavior you need; do not treat the current-window method as full-page capture.

Or skip the browser setup

If you need a screenshot from a URL rather than a Selenium-controlled session, ScreenshotNeo offers a website screenshot API and MCP server. Its API accepts a URL in a GET request and returns an image or PDF. See the ScreenshotNeo website and 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://stripe.com -o shot.webp

With Python, the same endpoint can return the response body for your program to save:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

For a Node.js request:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie and consent banners are accepted like a visitor, and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each of these steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include X-Page-Verdict and X-Billed headers.
  • An 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. Every feature is available on every plan.

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

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

Troubleshooting

The output file is empty or not a valid image

Check that the browser capture completed before writing the result, and make sure the program writes the returned png_bytes without converting them to text. Open the file in "wb" mode and use a .png filename. If you use a separate image-processing or upload library, verify that it receives the raw bytes or a supported binary stream, not a base64 string.

The method fails because there is no active session

get_screenshot_as_png() is called on a WebDriver instance. Create the driver successfully and navigate to a page before requesting a capture. If a previous test step has already closed the session, start or reuse a live driver session rather than calling the method on the closed one.

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.

The file is not where you expected

A relative filename is resolved from the process’s current working directory, which may differ from the script’s directory. Print or inspect the resolved destination in your own program, create the parent directory before writing, or provide an absolute path. Also check filesystem permissions and whether the destination is writable.

The screenshot omits content below the visible window

That is consistent with the documented current-window scope. This method does not guarantee a full-page capture. Choose a separate full-page technique supported by your browser and driver, and verify its behavior in that environment.

You need a file but not in-memory processing

Use save_screenshot(path) or get_screenshot_as_file(path), then check the returned boolean. This avoids writing your own byte-to-file code.

Practical checklist

  • Call the method on an active driver after the page is in the state you intend to capture.
  • Use get_screenshot_as_png() for in-memory PNG bytes; use binary mode if saving those bytes yourself.
  • Use a direct-save method if the only goal is a PNG file, and check its boolean result.
  • Use get_screenshot_as_base64() only when the next step expects base64 text.
  • Confirm separate support for element or full-page capture rather than assuming the current-window method covers those scopes.

Frequently Asked Questions

Does get_screenshot_as_png() require Pillow?

No. Selenium returns the PNG as Python bytes. Pillow is optional if you want to inspect or transform the image after capture.

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

Can I use the returned bytes after closing the browser?

Yes. Once assigned to a Python variable, the bytes are in memory and can be used independently of the WebDriver session.

Does this method return JPEG data?

No. The method is specifically the PNG screenshot method; use a separate image-conversion step if another format is 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.