In Selenium Python, save the current browser window as a PNG with driver.save_screenshot("screenshot.png"). Its documented equivalent is driver.get_screenshot_as_file("screenshot.png"). For Java, use TakesScreenshot and call getScreenshotAs. These commands capture the current window; they do not automatically mean “capture the entire page.”
Python: save the current browser window
Call the screenshot method on your WebDriver instance after navigating to the page and after the content you want is visible:
driver.save_screenshot("screenshot.png")
The Python API describes this as saving a screenshot of the current window to a PNG image file. Use a filename ending in .png. The method returns True when it saves the file and False if an I/O error prevents the save, so checking the result is useful in scripts that must produce an artifact reliably.
ok = driver.save_screenshot("artifacts/home.png")
if not ok:
raise IOError("Screenshot could not be written")
The destination is interpreted by the process running the Selenium code. A relative path such as artifacts/home.png is relative to that process’s working directory, not necessarily the directory containing your source file. Create the parent directory before saving if it may not exist, or provide an absolute path.
#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.
Equivalent file method
You can also use get_screenshot_as_file for the same current-window PNG use case:
saved = driver.get_screenshot_as_file("artifacts/home.png")
if not saved:
raise IOError("Screenshot could not be written")
Choose one method and use it consistently; calling both one after the other normally just writes two captures of the same browser state. If you need to preserve the screenshot in memory instead of writing it immediately, use one of the data-returning methods below.
Keep the screenshot in memory instead of saving a file
Python exposes two alternatives when your next step is to upload, attach, transform, or otherwise process the image without first writing it to disk:
driver.get_screenshot_as_png()returns PNG image data as bytes.driver.get_screenshot_as_base64()returns the screenshot as a base64-encoded string.
png_bytes = driver.get_screenshot_as_png()
base64_image = driver.get_screenshot_as_base64()
Use the bytes form when the receiving code accepts binary image data. Base64 is useful when the consumer expects text, such as an image data field in a JSON workflow, but it encodes the image as text and is not itself a PNG file on disk. If you do need a file from the bytes, write them in binary mode:
Recommended Free Tools
png_bytes = driver.get_screenshot_as_png()
with open("artifacts/home.png", "wb") as image_file:
image_file.write(png_bytes)
The bytes and base64 methods avoid the file-save return value, so handle errors from the WebDriver call and from any later processing or write operation in your own code.
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.
Java: use the TakesScreenshot interface
In Java, the common pattern is to cast the driver to Selenium’s TakesScreenshot interface and request a file output:
File screenshotFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
The interface supports different output types, including OutputType.FILE and OutputType.BASE64. A typical file workflow obtains the temporary screenshot file and then copies it to the destination your application wants. The copy operation is separate from asking the driver to take the screenshot, so handle both capture and filesystem failures.
File screenshotFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
File destination = new File("artifacts/home.png");
Files.createDirectories(destination.toPath().getParent());
Files.copy(screenshotFile.toPath(), destination.toPath(),
StandardCopyOption.REPLACE_EXISTING);
This example uses java.io.File, java.nio.file.Files, and java.nio.file.StandardCopyOption; include their imports and Selenium’s screenshot types in your class. The driver must already be created and positioned on the page you intend to capture. Unlike the Python file method, this Java example returns a file object and relies on Java exceptions for failures; surround it with appropriate exception handling for your application.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Request base64 in Java
If the next step needs a base64 string rather than a file, request that output type directly:
String screenshotBase64 = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BASE64);
This gives you encoded screenshot data. It does not create a destination file; decode or pass the string onward only if the receiving code expects that representation.
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.
What part of the page does Selenium capture?
The ordinary Python calls above capture the current browser window. In practical terms, use them when the relevant page state is already in the visible browser area. Do not assume that the generic screenshot command means a full-page image extending through all content below the viewport.
Capture a WebElement in Java
The Java API’s TakesScreenshot interface can also be implemented by an HTML element. That permits requesting a screenshot from a WebElement, rather than from the whole driver:
File elementScreenshot = ((TakesScreenshot) element)
.getScreenshotAs(OutputType.FILE);
Element-level capture is not equally reliable across every browser and driver combination. For non-W3C drivers, the documented capture scope is best effort and browser-dependent. If an element capture is cropped unexpectedly or unsupported, use a driver-level screenshot or verify support for the specific browser and driver you run rather than assuming the element method has identical behavior everywhere.
Capture a full document in Firefox Python
Firefox’s Python WebDriver offers separate full-document methods: get_full_page_screenshot_as_file and save_full_page_screenshot. For example:
driver.save_full_page_screenshot("artifacts/full-page.png")
Use the Firefox-specific method when the requirement is a document-wide capture beyond the currently visible window. It is a distinct API from save_screenshot; do not assume the generic method will scroll or stitch the whole page for you.
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
Choose the output and scope that match the job
| Need | Use | Result or qualification |
|---|---|---|
| Save the visible browser window in Python | driver.save_screenshot("shot.png") or driver.get_screenshot_as_file("shot.png") |
PNG file; Python method returns a Boolean indicating save success. |
| Keep image data in Python memory | get_screenshot_as_png() or get_screenshot_as_base64() |
PNG bytes or base64 text. |
| Capture from a Java driver | ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE) |
File output; Java failures are reported through exceptions. |
| Get encoded image data in Java | getScreenshotAs(OutputType.BASE64) |
Base64 string, not a saved file. |
| Capture an element in Java | Call getScreenshotAs on an element that implements TakesScreenshot |
Capture scope can be best effort and browser-dependent for non-W3C drivers. |
| Capture beyond the viewport in Firefox Python | save_full_page_screenshot or get_full_page_screenshot_as_file |
Firefox-specific full-document screenshot API. |
Make the screenshot useful and repeatable
A screenshot records the browser state at the moment the command runs. If an automation step is still navigating, rendering, or updating content, the image may show an incomplete state even when the screenshot call itself succeeds. Place the capture after the navigation and the specific interaction or condition your test is meant to verify. When the page includes dynamic content, wait for the relevant element or state in your existing Selenium flow before capturing; a fixed delay is not a substitute for verifying that the expected content appeared.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use predictable paths for test artifacts. A directory dedicated to screenshots makes it easier to attach failures to CI runs or compare them with expected results. Ensure the directory exists, give each capture a meaningful name, and decide whether a later run should overwrite an earlier image or keep a separate artifact. For Python, check the returned Boolean when writing with the file methods. For Java, handle exceptions from capture and from copying the returned file.
For parallel test runs, avoid having multiple tests write the same filename: one capture can overwrite another or make the result ambiguous. Include a test identifier or other unique context in the path. Keep the browser session alive until the screenshot operation is complete, and do not confuse a screenshot of the current window with a full-document capture requirement.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common screenshot problems
The screenshot file is missing
- Check the output path. Relative paths resolve from the Selenium process’s working directory. Print or inspect that directory, or switch to an absolute path.
- Create the parent directory. A filename in a directory that does not exist cannot be written. Create it before calling the screenshot method.
- Check Python’s Boolean result. A
Falsereturn fromsave_screenshotorget_screenshot_as_fileindicates that an I/O error prevented saving. - Check Java’s copy step too. Obtaining a temporary screenshot file and copying it to your desired destination are separate operations; either can fail.
The image is blank or shows the wrong state
Confirm the browser navigated to the intended URL and that the screenshot command runs after the content or interaction under test. If the page updates asynchronously, wait for a meaningful page condition before capture. A successful file write only establishes that image data was saved; it does not prove that the browser had reached the intended visual state.
The capture omits content below the fold
The standard Python command captures the current window, not necessarily the complete document. If you need a full-page screenshot in Python, the available full-document methods are Firefox-specific. Otherwise, ensure your requirement and chosen browser API actually support the desired capture scope; do not treat scrolling the page and taking one ordinary screenshot as a full-page capture.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBest 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.
An element screenshot is unsupported or cropped differently
Element capture depends on driver and browser support, and the Java interface documents best-effort, browser-dependent scope for non-W3C drivers. Verify the actual browser-driver combination. When precise element capture is unavailable, consider capturing the current window and handling the crop in a separate image-processing step.
The Python script reports failure despite a valid browser window
Separate browser capture from local file writing. Try a simple known-writable absolute path and inspect the Boolean result. If you only need to pass the image onward, use get_screenshot_as_png() and test the downstream handling independently of the filesystem.
Or skip the browser setup
If you need a screenshot from a URL without creating or managing a Selenium browser session, ScreenshotNeo provides a screenshot API and MCP server. One GET request returns an image or PDF; see the API documentation for parameters and response details.
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, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for the free plan.
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 minuteFrequently Asked Questions
Does save_screenshot return the image?
No. It writes a PNG file and returns a Boolean indicating whether the save succeeded. Use get_screenshot_as_png() for image bytes or get_screenshot_as_base64() for encoded text.
Can Selenium take a screenshot of an HTML element?
In Java, an element may implement TakesScreenshot, allowing getScreenshotAs on the element. The capture scope is best effort and browser-dependent for non-W3C drivers.
Does the regular Selenium screenshot command capture the entire page?
The normal Python screenshot command captures the current browser window. Firefox Python has separate full-document screenshot methods.
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.

