To screenshot the application currently open in Selenium, call the screenshot method on the active WebDriver session. In Python, use driver.save_screenshot("screenshot.png"). Selenium captures the current browsing context, so first switch to the intended tab or window if the application is open somewhere other than the active context.
What “current application” means in Selenium
Selenium does not take a screenshot of an application by its name. It captures the browsing context selected by the WebDriver session: in a typical browser test, that means the active tab or window. The Selenium documentation describes the target as the “current browsing context.” See Working with windows and tabs.
That distinction matters when a test opens a second tab, launches a new window, or switches between applications. Before taking the screenshot, make sure the driver is focused on the context you want. The basic Python call saves a PNG file:
driver.save_screenshot("screenshot.png")
This is a screenshot of the current browser context, not a guarantee of a complete, stitched image of every part of a long page. If you need a particular element instead of the browser view, use an element screenshot method.
Free tools Windows power users keep installed
One-click scans. No signup required.
#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.
Take and save a screenshot in Python
The following example opens a page, captures the active browser context, checks whether the file was saved, and closes the browser. It assumes Python and the Selenium package are installed and that a compatible browser and driver are available to Selenium.
from pathlib import Path
from selenium import webdriver
output = Path("artifacts") / "screenshot.png"
output.parent.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
saved = driver.save_screenshot(str(output))
if not saved:
raise OSError(f"Selenium could not save the screenshot to {output}")
print(f"Saved screenshot to {output.resolve()}")
finally:
driver.quit()
Replace https://example.com with the application URL. The screenshot path is relative to the process’s current working directory unless you provide an absolute path. The file API writes PNG output; Selenium’s Python API also provides methods for obtaining screenshot data without first writing a file. The documented Python WebDriver API is for version 4.49.0: Python WebDriver API.
Capture only after the page is ready
A screenshot records what is rendered when the command runs. If the application still has a loading indicator, animation, or delayed content, wait for a meaningful condition before capturing. For example, an explicit wait can ensure a known application element is visible:
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
WebDriverWait(driver, 15).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)
Path("artifacts").mkdir(exist_ok=True)
if not driver.save_screenshot("artifacts/ready.png"):
raise OSError("Screenshot could not be saved")
finally:
driver.quit()
Choose a selector that indicates the state you actually need; a visible main element, for example, does not necessarily prove that every image or asynchronous component has finished loading.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteRank #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.
Switch to the right tab or window first
Selenium treats tabs and windows through window handles. When a new tab or window opens, switch the driver to its handle before capturing. Otherwise the screenshot may show the previous page, even though the new tab is visible to you outside the WebDriver’s selected context.
from selenium import webdriver
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
original = driver.current_window_handle
# Perform the action that opens another tab or window.
# For example, click a link in the application here.
# Wait for the new handle, then select it.
WebDriverWait(driver, 10).until(lambda d: len(d.window_handles) > 1)
new_handle = next(h for h in driver.window_handles if h != original)
driver.switch_to.window(new_handle)
if not driver.save_screenshot("new-context.png"):
raise OSError("Screenshot could not be saved")
finally:
driver.quit()
To run this pattern as written, add these imports at the top:
from selenium.webdriver.support.ui import WebDriverWait
The example leaves the action that opens the new context as a placeholder because the correct action depends on your application. Do not copy the leading space before driver in the first line of the main example; Python indentation must be consistent. For a complete, minimal switch example with the imports in place:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
original = driver.current_window_handle
# Trigger an action here that opens the intended second tab/window.
WebDriverWait(driver, 10).until(lambda d: len(d.window_handles) > 1)
target = next(handle for handle in driver.window_handles if handle != original)
driver.switch_to.window(target)
driver.save_screenshot("target-window.png")
finally:
driver.quit()
When the test is finished with the second context, switch back using driver.switch_to.window(original) if later test steps should continue in the original tab.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.
Choose the right screenshot target and output
| Need | Use | What to expect |
|---|---|---|
| Save the current browser view as an image file | Python driver.save_screenshot(path) |
Writes a PNG file; the method returns False if the file cannot be written. |
| Process image bytes in Python | driver.get_screenshot_as_png() |
Returns PNG data for in-memory processing rather than requiring a saved file first. |
| Pass an encoded image from Python | driver.get_screenshot_as_base64() |
Returns base64-encoded screenshot data. |
| Capture one HTML element | Call the screenshot method on the element | Targets that element rather than the whole current browser context. |
The Python methods and their output forms are documented in the Python WebDriver API. Use a file when a test artifact is the goal; use bytes or base64 when the next step consumes the image directly.
Element-only screenshot in Python
Locate the element after the page reaches the required state, then call its screenshot method:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
card = driver.find_element(By.CSS_SELECTOR, "main")
if not card.screenshot("main-element.png"):
raise OSError("Element screenshot could not be saved")
finally:
driver.quit()
Choose an element locator that uniquely identifies the intended region. An element capture is a different target from the current application view, and should not be treated as a full-window capture.
Java and JavaScript equivalents
If your test suite uses another binding, the same basic rule applies: select the intended window or tab, then request the screenshot. The exact return type and file-writing step differ by language.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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
Java: write the returned file to your chosen path
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CaptureScreenshot {
public static void main(String[] args) throws IOException {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
File source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Path destination = Path.of("artifacts", "screenshot.png");
Files.createDirectories(destination.getParent());
Files.copy(source.toPath(), destination);
} finally {
driver.quit();
}
}
}
The Java API uses TakesScreenshot and lets the caller request output such as a file. See Java TakesScreenshot API for the interface and its implementation notes.
JavaScript: receive base64 PNG data
const { Builder } = require('selenium-webdriver');
const fs = require('node:fs/promises');
(async () => {
const driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('https://example.com');
const pngBase64 = await driver.takeScreenshot();
await fs.writeFile('screenshot.png', Buffer.from(pngBase64, 'base64'));
} finally {
await driver.quit();
}
})();
In the JavaScript WebDriver API, takeScreenshot() returns a base64-encoded PNG string. The binding documentation describes screenshot extent as best effort: JavaScript WebDriver API.
Viewport, window, and full-page expectations
Do not assume that calling a driver screenshot method always produces a full-page image. Screenshot extent can depend on the browser, driver, and implementation. The JavaScript API describes a best-effort order that may include the entire page, current window, visible portion of the current frame, or entire display containing the browser. The Java API gives corresponding best-effort notes for non-W3C-conformant implementations and distinguishes behavior for conformant drivers and elements.
For a normal test artifact, treat the result as a screenshot of the current context and verify its extent in the browser/driver combination you actually run. If full-page coverage is a requirement, inspect a sample output from that configured environment rather than relying on a cross-browser guarantee that the APIs do not make. See the JavaScript API and Java API.
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.
Troubleshooting missing or incorrect screenshots
- The image shows the wrong page. The driver is likely still selected on another tab or window. Check
driver.current_window_handleanddriver.window_handles, then switch to the intended handle before capture. - No file appears. Check the process’s working directory and use an absolute path to eliminate ambiguity. Create the destination directory first. In Python, inspect the boolean result from
save_screenshot(); it returnsFalseon an I/O error. - The screenshot shows a loading state. Wait for an application-specific condition before capturing. A fixed delay can work for a known demo, but a wait for the actual visible state is generally a more meaningful test condition.
- The image is not full-page. This can be an implementation or driver behavior difference. Selenium documents best-effort extent rather than a universal full-page outcome; verify with the browser and driver configured for the test.
- The element capture fails or misses the target. Confirm the locator resolves to the intended element and that the element exists in the current context before calling its screenshot method.
- The browser does not close after an error. Put screenshot and test work inside
try/finallyand calldriver.quit()in thefinallyblock so cleanup still runs.
Or skip the browser setup
If you need an image of a URL rather than a screenshot from Selenium’s already-running browser session, ScreenshotNeo can capture it with one GET request. It is a website screenshot API and MCP server by Yorker Media. This remote URL capture is an alternative to setting up a browser for the capture; it does not take a screenshot from the live WebDriver session shown above.
cURL example, saving a WebP response to a file:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python equivalent:
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)
Node.js equivalent:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the ScreenshotNeo documentation for API details. Its cookie/consent-banner handling and removal of known consent platforms, newsletter popups, and chat widgets can be turned off; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with response headers indicating the page verdict and billing status. It also offers an MCP server for AI agents, including Claude and Cursor. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Sign up free for 1,000 screenshots a month with no card required.
Frequently Asked Questions
Can Selenium take a screenshot of an element instead of the whole browser view?
Yes. Use the screenshot method on the located element when the target is one HTML element rather than the current browsing context.
Does Selenium’s Python screenshot method create a JPEG?
The documented driver screenshot methods described here produce PNG output or PNG data; the file method saves a PNG.
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.

