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

Direct answer: Python can screenshot an “open website” when that page is controlled by a browser-automation session. In Playwright, call page.screenshot(path="screenshot.png"); in Selenium, call driver.save_screenshot("screenshot.png"). These APIs capture the page or window owned by that session—not an unrelated tab already open in another browser process.

This guide shows working Playwright and Selenium code, viewport versus full-page and element captures, in-memory output, asynchronous Playwright, troubleshooting, and a browser-free API option.

What “open website” means in Python

A normal Python process cannot take over an arbitrary tab that happens to be visible on your desktop. The browser must be launched or connected through an automation library, and the library must expose a page or WebDriver window. Once you have that object, the screenshot call captures its current state.

  • Playwright: a Page represents one browser tab and supports viewport, full-scrollable-page, and locator screenshots.
  • Selenium: a WebDriver controls a browser window and provides PNG file, bytes, and Base64 screenshot methods.

If you already have a Playwright Page or Selenium driver in your program, you can use the final screenshot call directly. If not, the examples below create a controlled browser session first.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Choose Playwright or Selenium

Decision Playwright Python Selenium Python
Basic call page.screenshot(path="screenshot.png") driver.save_screenshot("screenshot.png")
Capture target Page viewport, full page, or locator/element Current WebDriver window (the cited API documents window capture)
In-memory output Returns screenshot bytes when no path is supplied PNG bytes or Base64 through dedicated methods
Save feedback Bytes are returned; file writing is performed by the call File method returns False on an I/O error
Programming styles Sync and async APIs Python WebDriver API

Playwright is convenient when you need full-page or element screenshots with one API. Selenium is a practical choice when your project already uses WebDriver, an existing Grid, or Selenium-specific tooling.

Playwright: screenshot an open page

Install Playwright and a browser

Install the Python package, then install the browser binaries used by Playwright:

python -m pip install playwright
python -m playwright install

The second command is required on a new machine unless the required browser binaries are already installed.

Complete synchronous example

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    page.screenshot(path="screenshot.png")
    browser.close()

This launches Chromium, navigates to the URL, captures the current viewport, and writes screenshot.png in the process’s working directory. To capture a page your code has already opened, omit the launch and navigation steps and call page.screenshot(path="screenshot.png") after the page reaches the desired state.

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

Full-page screenshot

page.screenshot(path="full-page.png", full_page=True)

full_page=True captures the page’s full scrollable height instead of only the visible viewport. Very long pages can create large images; consider resizing or capturing sections when downstream systems have image-size limits.

Capture one element

page.locator(".header").screenshot(path="header.png")

Replace .header with a CSS selector for the element you need. A locator screenshot is useful for a component, chart, table, or a regression-test target without including the rest of the page.

Return bytes instead of writing a file

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

With no path, Playwright returns the image bytes. You can upload those bytes to object storage, attach them to a test report, or send them through an API without a temporary file.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Choose PNG, JPEG, or WebP

Playwright infers the format from the path extension. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.screenshot(path="view.jpeg", quality=85)
page.screenshot(path="view.webp", quality=85)

Quality applies to lossy JPEG and WebP output. PNG is lossless and does not use a quality setting. Use a valid extension and verify that the consumers of the file support the selected format.

Asynchronous Playwright

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch()
        page = await browser.new_page()
        await page.goto("https://example.com")
        await page.screenshot(path="async-shot.png")
        await browser.close()

asyncio.run(main())

Keep the async style consistent: navigation and screenshot operations are awaited. Mixing synchronous Playwright calls into an async event loop can produce confusing runtime errors.

Selenium: screenshot the current WebDriver window

Install Selenium and start a session

python -m pip install selenium

Recent Selenium releases can manage compatible browser drivers in common setups. If your environment requires a separately managed driver or Grid endpoint, configure that before creating the driver.

Complete example

from selenium import webdriver

options = webdriver.ChromeOptions()
# options.add_argument("--headless=new")  # optional for servers

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    ok = driver.save_screenshot("screenshot.png")
    if not ok:
        raise OSError("Could not save screenshot")
finally:
    driver.quit()

save_screenshot saves the current WebDriver window as a PNG file. The Boolean result lets you detect an I/O failure instead of silently continuing with a missing image.

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.

Get PNG bytes or Base64

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

base64_image = driver.get_screenshot_as_base64()

Use PNG bytes when another Python component accepts binary data. Base64 is convenient for JSON payloads or inline transport, but it is larger than the original binary.

Capture an existing Selenium page

If another function already navigated the driver, call driver.save_screenshot("current.png") at the point where the page is ready. Selenium’s cited API documents the current window capture; do not assume that this call automatically creates a full, vertically stitched page.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Make the capture represent the page you need

Wait for navigation and dynamic content

A screenshot taken immediately after a navigation request can catch a loading state. In Playwright, page.goto waits for its navigation condition, but client-side rendering may continue afterward. Wait for a meaningful selector before capturing:

page.goto("https://example.com/dashboard")
page.locator(".dashboard").wait_for()
page.screenshot(path="dashboard.png")

In Selenium, wait explicitly for an element when the application renders asynchronously:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

wait = WebDriverWait(driver, 30)
driver.get("https://example.com/dashboard")
wait.until(lambda d: d.find_element(By.CSS_SELECTOR, ".dashboard"))
driver.save_screenshot("dashboard.png")

Control viewport and device scale

Set a predictable viewport in Playwright when comparing screenshots across runs:

browser = playwright.chromium.launch()
context = browser.new_context(viewport={"width": 1440, "height": 900}, device_scale_factor=1)
page = context.new_page()

Without a fixed viewport, a headed browser’s window size or a CI environment can change line wrapping and responsive layout. Selenium exposes window sizing through the driver, for example driver.set_window_size(1440, 900).

Handle authentication and state

For private pages, establish the login state in the same controlled session before taking the shot. A screenshot API cannot infer credentials from a different browser profile unless you explicitly connect or transfer the required cookies and storage state.

Use safe, deterministic paths

Resolve output paths relative to a known directory, create that directory first, and avoid filenames containing user-controlled URL text. On CI, save artifacts to the directory your runner preserves.

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

Common errors and fixes

  • “Browser executable not found” (Playwright): run python -m playwright install, or configure Playwright to use an installed executable.
  • Driver or browser version mismatch (Selenium): update Selenium and the browser/driver pair, or point the driver at the compatible remote endpoint used by your environment.
  • Blank or partially rendered image: wait for a page-specific selector, fonts, images, or application data before calling the screenshot method.
  • Consent banner, chat bubble, or newsletter popup appears: dismiss it in the automated session before capture, or hide the relevant selectors in your test setup.
  • File is missing: check the process working directory and write permissions. In Selenium, treat a False return from save_screenshot as an error.
  • Screenshot is unexpectedly cropped: use Playwright’s full_page=True for a full scrollable page, or capture the specific locator you need.
  • Timeout while loading: verify DNS, proxy, authentication, and the target’s availability. Increase a library timeout only after identifying the slow operation.
  • Python event-loop error: use Playwright’s synchronous API in synchronous code and its async API with await inside an async function.

Performance, reliability, and cost considerations

Launching a browser for every image adds startup time. For batches, reuse one browser process and context where isolation requirements permit, then create or close pages per URL. Keep navigation and element waits bounded so one broken site does not stall a queue indefinitely.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Full-page images consume more memory than viewport captures, especially on long documents or high device scale factors. Prefer element captures for focused tests and choose JPEG or WebP when smaller lossy files are acceptable. For reproducible visual comparisons, fix the viewport, browser version, locale, timezone, and authentication state.

Self-hosted Playwright or Selenium costs the compute and browser maintenance of your environment. A hosted screenshot endpoint shifts browser execution to a service and can be simpler for scheduled jobs, webhooks, and large URL lists; evaluate its billing and failure semantics before switching.

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

Or skip the browser setup: ScreenshotNeo

ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF, so your Python program does not need to install or manage a local browser.

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.
import requests

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

See the ScreenshotNeo documentation for request options and response details. The service accepts the consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing result in X-Page-Verdict and X-Billed headers.

For AI workflows, its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Features include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, request/resource blocking, headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, async jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Common parameter names used by other screenshot APIs also work.

Plan Included shots Price
Free 1,000 per month $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free, and every feature is available on every plan. If you want to try the API without a card, sign up for ScreenshotNeo’s free plan and get 1,000 screenshots per month.

FAQ

Can Python screenshot a tab I opened manually?

Not with the basic Playwright or Selenium calls. The tab must belong to, or be connected through, an automation session that Python controls.

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

Which format should I use for test artifacts?

Use PNG when lossless pixels matter. JPEG or WebP can reduce file size when small visual differences are acceptable; Playwright selects the format from the filename extension.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

How do I capture a screenshot for a report without saving locally?

Use Playwright’s returned bytes or Selenium’s get_screenshot_as_png(), then pass the bytes to your report, storage, or HTTP client.

Does Selenium’s basic screenshot call capture the entire page?

The cited Selenium API describes saving the current window. Use Playwright’s documented full_page=True when you specifically need a full scrollable-page capture.

Frequently Asked Questions

Can Python screenshot a tab I opened manually?

Not with the basic Playwright or Selenium calls. The tab must belong to, or be connected through, an automation session that Python controls.

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

Which format should I use for test artifacts?

Use PNG when lossless pixels matter. JPEG or WebP can reduce file size when small visual differences are acceptable; Playwright selects the format from the filename extension.

How do I capture a screenshot for a report without saving locally?

Use Playwright’s returned bytes or Selenium’s get_screenshot_as_png(), then pass the bytes to your report, storage, or HTTP client.

Does Selenium’s basic screenshot call capture the entire page?

The cited Selenium API describes saving the current window. Use Playwright’s documented full_page=True when you specifically need a full scrollable-page capture.

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.