For most Python projects, Playwright’s built-in screenshot API is the best place to start: use page.screenshot() for a viewport or full-page image, and locator.screenshot() for one element. If screenshots are test-failure artifacts, use the Playwright pytest plugin; if you need to understand the actions and page state behind an image, record a trace and inspect it in Trace Viewer. These are complementary Playwright workflows, not interchangeable standalone products.
Which Playwright screenshot workflow should you use?
| Workflow | Best for | What you get |
|---|---|---|
page.screenshot() |
A direct capture of the page viewport or the full scrollable page | An image file or image bytes |
locator.screenshot() |
A button, component, or other specific element | An image of the located element |
| Playwright pytest plugin | Automatically saving evidence from test runs, especially failures | Test screenshot artifacts |
| Tracing and Trace Viewer | Diagnosing how a visual state arose | A trace archive with screenshots, DOM snapshots, actions, and debugging context |
| ScreenshotNeo | A hosted screenshot API or MCP server when you do not want to run a browser in your Python project | PNG, JPEG, WebP, or PDF from one GET request; clean shots only are billed |
Take a screenshot with Playwright Python
Install Playwright and its browser binaries, then create a page and call its screenshot method. The official Python screenshots guide describes a full-page image as “a screenshot of a full scrollable page, as if you had a very tall screen and the page could fit it entirely.” See the Playwright Python Screenshots documentation for the API and examples.
Install and run a synchronous example
python -m pip install playwright
python -m playwright install chromium
from pathlib import Path
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page(viewport={"width": 1440, "height": 900})
page.goto("https://example.com", wait_until="networkidle")
page.screenshot(path="page.png")
page.screenshot(path="full-page.png", full_page=True)
image_bytes = page.screenshot() # Returned as bytes when path is omitted
Path("page-copy.png").write_bytes(image_bytes)
browser.close()
Use the project’s actual target URL in place of https://example.com. Set the viewport on the page’s browser context to make the requested CSS viewport dimensions explicit; defaults can vary by setup. For production scripts, close the browser in a finally block if errors may occur before the last line.
Use async when the surrounding project uses asyncio
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
context = await browser.new_context(viewport={"width": 1440, "height": 900})
page = await context.new_page()
await page.goto("https://example.com", wait_until="networkidle")
await page.screenshot(path="page.png")
await page.screenshot(path="full-page.png", full_page=True)
await browser.close()
asyncio.run(main())
Keep the synchronous and asynchronous styles consistent within a script; the Playwright Python library supports both. See Getting started with the Playwright Python library.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- 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 image format and scale deliberately
The screenshot API accepts output type and scale options. Use scale="css" for one image pixel per CSS pixel; device scale can produce larger output on high-DPI configurations. If you need WebP, Playwright’s release notes report support for page.screenshot() and locator.screenshot() in version 1.62, including inference from a .webp filename or an explicit type option. Confirm the installed version before relying on it; see Playwright Python release notes.
Capture one element instead of the whole page
For a specific component, call screenshot() on a locator rather than taking a page image and cropping it afterward. Locator screenshots wait for actionability and scroll the element into view. The locator API is preferred to the discouraged ElementHandle.screenshot(); options include type, scale, animations, and style. See the Playwright Locator API.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page(viewport={"width": 1280, "height": 800})
page.goto("https://example.com")
card = page.locator(".product-card").first
card.screenshot(path="product-card.png", animations="disabled", scale="css")
browser.close()
Replace .product-card with a selector that identifies the element you need. A locator screenshot captures the element, not all of its descendants if they extend beyond a scrollable container’s currently visible content. An element obscured by another element may also fail to appear as expected. If the selector matches nothing, check the page state and selector before increasing timeouts.
Rank #2
- 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.
Make captures more repeatable
For comparisons or test artifacts, fix the viewport and reduce transient visual changes. Playwright exposes screenshot controls for animations and styles; for example, disable animations or apply a screenshot-only stylesheet to hide a timestamp or normalize a dynamic region. Use these controls only when hiding that content is appropriate to the purpose of the capture.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →- Set a known context viewport instead of relying on defaults. Context options are covered in the Browser API.
- Wait for a meaningful application condition, such as a locator becoming visible, rather than assuming navigation completion means the page is visually ready.
- Use
animations="disabled"or the screenshotstyleoption when motion or known dynamic content makes an image unsuitable for comparison. - Do not assume identical pixels across operating systems, fonts, browser builds, or application states. The API provides controls, but it does not promise universal pixel-perfect determinism.
Save screenshots automatically from pytest
When the goal is test-run evidence, the Playwright pytest plugin can capture screenshots automatically and can be configured for full-page screenshots on failure. Use the plugin’s documented CLI options with its default fixtures. The full-page-on-failure option depends on screenshot capture being enabled; consult the Playwright Python pytest plugin reference for current argument names and setup.
A key limitation: plugin CLI arguments apply to default fixtures. They do not automatically configure browser, context, or page objects that your test creates manually. If you construct those objects yourself, add screenshot logic to your own failure handling or use the plugin’s fixtures as documented. This distinction often explains why an expected artifact is missing even though a command-line flag was supplied.
Rank #3
- 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.
Use traces when the screenshot needs context
A screenshot records pixels at one moment; it does not by itself show what actions led there or the corresponding DOM state. For visual debugging, record a Playwright trace with screenshots and snapshots, then open the archive in Trace Viewer. The viewer can present screenshots in an action timeline alongside action details, DOM snapshots, source locations, and logs. Follow the Trace Viewer documentation for the current capture and viewing workflow.
Choose tracing when a failing or unexpected image needs an explanation, not merely a saved PNG. For a single uncomplicated image, a direct screenshot call is simpler and produces an image file rather than a diagnostic trace archive.
Recommended Free Tools
Or skip the browser setup
If you want a hosted screenshot rather than managing Playwright and browser binaries, ScreenshotNeo accepts a URL in one GET request and returns an image or PDF. Its API and options are documented at ScreenshotNeo documentation.
Rank #4
- 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
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
- It accepts cookie/consent banners before capture and removes known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Each response identifies the page verdict and billing status in headers.
- An MCP server exposes screenshot, page-info, and PDF-capture tools to Claude, Cursor, and other MCP clients.
- The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.
Create a free ScreenshotNeo account to try it with 1,000 screenshots per month and no card.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting Playwright screenshots
The screenshot is blank or incomplete
- Cause: The capture starts before the page has rendered the content you need. Fix: Wait for a relevant locator or application-ready condition before capturing; navigation completion alone may not mean all dynamic content is ready.
- Cause: Lazy-loaded content has not been brought into view. Fix: Scroll through the relevant page or element before capture, then verify the resulting image.
- Cause: A full-page capture was not requested. Fix: Pass
full_page=Truetopage.screenshot(); this option is for the whole scrollable page, not an element locator.
An element screenshot fails or misses content
- Cause: The locator does not resolve to the intended element, or the target is covered. Fix: Check the selector, visibility, and overlays; locator screenshots scroll the element into view, but cannot make an obscured element visible.
- Cause: The target is inside a scrollable container. Fix: Scroll that container to the content you need; only its currently scrolled content is captured.
A pytest failure did not produce the expected full-page artifact
Confirm screenshot capture is enabled as well as the full-page-on-failure setting. If the test uses manually created browser, context, or page objects, plugin CLI arguments will not configure them automatically; use the plugin’s default fixtures or implement capture for those objects.
The image differs between runs or machines
First control the viewport, page readiness, animations, and known dynamic content. Then compare browser build, operating system, and font availability. Playwright’s screenshot controls help stabilize a particular setup but do not establish identical output across different environments.
Best Value
- 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.
Performance, reliability, and cost considerations
Playwright captures run in the browser process your script launches, so you control the browser, page state, output path, and integration with tests. That also means your project must install and manage Playwright’s browser binaries and handle navigation failures, timeouts, and cleanup. Full-page images and high device-scale output can produce larger files than viewport captures; choose the scope and scale that match the consumer of the image. The official material does not establish a universal speed or quality winner among direct capture, pytest artifacts, and traces.
ScreenshotNeo instead provides hosted capture, with its stated billing rule that only clean shots are billed and its plans beginning at $5 for 3,000 shots; check its site for current plan details. Neither approach should be chosen on an assumed benchmark: select local Playwright for browser-level control and test integration, or the hosted API when avoiding local browser setup is more valuable.
Frequently Asked Questions
Does Playwright Python support both synchronous and asynchronous screenshots?
Yes. The Python library provides sync and async APIs; use the style that fits the rest of your application.
Can I save a screenshot without writing a file directly?
Yes. When no path is supplied, the screenshot API returns image bytes that you can process or write elsewhere.
Quick Recap
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.




