Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
If Selenium fails around getScreenshotAs(OutputType.FILE), separate the problem into capture, API typing, and file-copy stages. The reliable pattern is to cast the driver to TakesScreenshot, obtain Selenium’s temporary file, and immediately copy it to a directory your application controls:
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
File source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destination = new File("./screenshot.png");
FileUtils.copyFile(source, destination);
OutputType.FILE does not write directly to ./screenshot.png. It returns a temporary file; your code must copy it before the JVM exits.
What OutputType.FILE actually returns
The Java API declares getScreenshotAs(OutputType<X> target) on TakesScreenshot, not on the general WebDriver interface. With OutputType.FILE, Selenium creates a temporary image file and returns a File reference. Selenium’s OutputType documentation states: “Obtain the screenshot into a temporary file that will be deleted once the JVM exits. It is up to users to make a copy of this file.”
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 →That lifecycle explains the common “file disappeared” report: the returned path is not a permanent test artifact. Copy it promptly, then use the destination path in reports or CI artifacts.
#1 Best Overall
- FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
- AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
- ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
- AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
- STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth
Use the documented Java pattern
Apache Commons IO version
Selenium’s Working with windows and tabs example uses Apache Commons IO. Add a compatible Commons IO dependency to the build if it is not already present, then use:
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public final class Screenshots {
private Screenshots() {}
public static void save(WebDriver driver, String path) throws IOException {
TakesScreenshot screenshotDriver = (TakesScreenshot) driver;
File source = screenshotDriver.getScreenshotAs(OutputType.FILE);
File destination = new File(path);
File parent = destination.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IOException("Could not create screenshot directory: " + parent);
}
FileUtils.copyFile(source, destination);
}
}
Call it after the page or state you need is visible:
Screenshots.save(driver, "build/screenshots/checkout.png");
Java NIO version without Commons IO
If you prefer not to add Commons IO, copy the temporary file with the JDK:
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public static void saveWithNio(WebDriver driver, Path destination) throws IOException {
File source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Path parent = destination.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
Files.copy(source.toPath(), destination, StandardCopyOption.REPLACE_EXISTING);
}
Handle IOException separately from a screenshot-capture exception. A successful capture followed by a failed copy points to the destination path, permissions, or filesystem—not to OutputType.FILE.
Rank #2
- Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
- 14" HD Display: 14.0-inch diagonal, HD (1366 x 768), micro-edge, anti-glare. See your digital world in a whole new way. Enjoy movies and photos with the great image quality and high-definition detail of 1 million pixels.
- Memory & Storage: 4 GB LPDDR4x & 64 GB eMMC Storage. Adequate high-bandwidth RAM to smoothly run multiple applications and browser tabs all at once. An embedded multimedia card provides reliable flash-based storage.
- Ports:2 x USB 3.0 Type-A,1 x USB 3.0 Type-C,1 x HDMI,1 x Headphone Jack
- Chrome OS: Chromebook is a computer for the way the modern world works, with thousands of apps. Enjoy the seamless simplicity that comes with Google Chrome and Android apps, all integrated into one laptop. It’s fast, simple, and secure.
Diagnose failures by stage
1. “Cannot resolve symbol” or “method not found” at compile time
- Verify the Selenium Java dependency is on the compile classpath.
- Import
org.openqa.selenium.OutputTypeandorg.openqa.selenium.TakesScreenshot, not similarly named classes from another package. - Use the interface explicitly when method resolution is unclear:
TakesScreenshot screenshotDriver = (TakesScreenshot) driver;
File source = screenshotDriver.getScreenshotAs(OutputType.FILE);
The cast is required because a variable declared only as WebDriver does not expose getScreenshotAs.
2. ClassCastException at runtime
The concrete object in driver does not implement TakesScreenshot in your current setup. Log the concrete class, browser, Selenium version, driver version, and whether a wrapper or remote proxy is involved. The API’s list of implementing drivers does not guarantee that every custom wrapper, proxy, or third-party driver supports screenshots. Do not “fix” this by changing the output filename; establish whether the object actually implements the interface.
3. WebDriverException from getScreenshotAs
Selenium documents WebDriverException when capture fails. Preserve the complete stack trace and record:
- browser and browser-driver versions;
- Selenium Java version;
- local versus remote execution;
- the current window, frame, and page state; and
- the exact command and exception message.
Capture failure happens before any file copy. A writable destination cannot repair a driver that never produced image data.
Rank #3
- Stunning 15.6" FHD IPS Display: Experience crisp 1920x1080 resolution on this 15.6 inch laptop with an IPS panel that delivers wide viewing angles and vivid colors. The narrow-bezel design maximizes screen real estate for comfortable viewing on this Win 11 laptop, whether you're studying or working.
- Celeron J4105 Processor & 256GB SSD: Powered by a reliable Celeron J4105 processor paired with 12GB DDR4 memory and a fast 256GB M.2 SSD. This laptop computer supports SSD expansion up to 2TB and TF card expansion up to 1TB, so your storage grows with your needs. Delivers smooth multitasking for daily productivity.
- AI-Powered Win 11 Laptop: Built-in AI features enhance your productivity with smart assistance for writing, summarizing, and task management. Pre-installed with Win 11 and includes Office 365 subscription. This student laptop is backed by 1-year warranty and 24/7 customer support.
- All-Day 7000mAh Battery & 180° Hinge: The high-capacity 7000mAh battery keeps this laptop powered through long classes or meetings. The 180-degree lay-flat hinge lets you share your screen effortlessly during presentations. This durable laptop computer adapts to your dynamic workflow.
- Versatile Connectivity Hub: Equipped with USB 3.2, Type-C, Mini HDMI, and 3.5mm audio jack to connect all your peripherals. Stay online anywhere with high-speed 5G WiFi and Bluetooth 4.2. This college laptop keeps you connected at home, in the library, or on the go.
4. UnsupportedOperationException
The concrete driver can report that screenshot capture is unsupported. Confirm support for that browser/driver combination and remove wrappers that hide the underlying implementation. There is no universal browser setting that fixes every unsupported implementation.
5. The file exists during the test but is gone later
That is expected if you retained Selenium’s temporary File instead of copying it. Copy to an application-controlled location before JVM shutdown, and point your test-report publisher at that destination. Also remember that new File("./image.png") is relative to the process working directory, which can differ between an IDE, Maven/Gradle, and a CI runner. Print destination.getAbsolutePath() when investigating.
6. Copy fails with “No such file,” “Access denied,” or a similar I/O error
- Check that the parent directory exists or create it with
Files.createDirectories. - Verify the CI user can write to the directory.
- Use an absolute path temporarily to rule out an unexpected working directory.
- Ensure the source file still exists at the moment of copying.
- Check disk space, container volume mounts, and Windows path escaping where applicable.
Choose the output type that fits your pipeline
| Output | Java type | Best use | Important caveat |
|---|---|---|---|
OutputType.FILE |
File |
Copying an image into a test-artifact or report directory | Temporary; copy it before JVM exit |
OutputType.BYTES |
byte[] |
Uploading raw PNG bytes or writing with your own storage code | Your application must persist or transfer the bytes |
OutputType.BASE64 |
String |
Embedding or transporting encoded image data | Your application must decode or handle the encoded value |
byte[] png = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
String encoded = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
These alternatives avoid Selenium’s temporary-file return form, but they do not remove your responsibility for storage, naming, upload errors, or retention.
Timing, page state, and screenshot extent
Take the screenshot only after the browser is in the intended state. Use an explicit wait for the element or condition that proves the page is ready rather than an arbitrary sleep. If the screenshot is blank or incomplete, investigate navigation, frame selection, lazy content, and overlays before blaming the output type.
Rank #4
- Efficient Performance for Everyday Computing: Powered by Intel N150 processor with up to 3.6 GHz Intel Turbo Boost Technology, 6 MB L3 cache, 4 cores, and 4 threads, this HP laptop delivers responsive performance for web browsing, streaming, document editing, and multitasking. Paired with 4GB LPDDR5 RAM and 128GB UFS storage, it handles daily tasks smoothly. Includes 1-year Microsoft 365 Personal subscription for Word, Excel, PowerPoint, and cloud storage to maximize your productivity.
- 14-Inch HD Micro-Edge Display:Enjoy clear visuals on the 14-inch HD (1366 x 768) anti-glare screen with 250-nit brightness and 62.5% sRGB coverage. The micro-edge bezel delivers a 79% screen-to-body ratio in a compact design. An HP True Vision 720p HD camera with noise reduction and dual-array microphones supports clear video calls, remote work, and online learning.
- Modern Connectivity and Wireless Technology: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.4 for seamless pairing with accessories. Versatile port selection includes 1 USB Type-C 10Gbps with DisplayPort 1.2 for external displays, 2 USB Type-A 5Gbps ports for peripherals, 1 HDMI 1.4b port, 1 headphone/microphone combo jack, and 1 multi-format SD media card reader. Connect monitors, transfer files quickly, and expand your workspace with ease.
- All-Day Battery Life and Portable Design: Enjoy up to 11 hours of video playback, 7.5 hours of mixed usage, or 7.5 hours of wireless streaming on a single charge, perfect for students and professionals on the go. Weighing just 3.24 lb and measuring 12.76" x 8.86" x 0.71", this lightweight laptop fits easily in backpacks and bags. The stylish willow green top cover with matte finish and natural silver keyboard deck with vertical brushing pattern offer a modern, professional look.
- AI-Enhanced Productivity: Access Microsoft Copilot instantly with the dedicated Copilot key for faster assistance. AI Noise Reduction filters background sounds and improves voice clarity during calls. Dual speakers provide clear audio, while the full-size natural silver keyboard and HP Imagepad support comfortable typing and navigation.
TakesScreenshot also describes element screenshots, but the captured extent depends on the API and implementation. The generic call should not be advertised as a guaranteed full-page capture across all browsers. Selenium documents a separate Firefox full-page screenshot API; verify its current method and supported browser/version before adopting it for a particular project.
Make the file-copy step reliable in CI
Use deterministic names
Include a test or request identifier in the destination filename, and avoid several parallel tests writing the same path. A per-run directory such as build/screenshots/<run-id>/ prevents collisions.
Keep capture errors distinct
File source;
try {
source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
} catch (RuntimeException captureError) {
// Record browser, driver, Selenium version, URL, and full stack trace.
throw captureError;
}
try {
Files.createDirectories(destination.getParent());
Files.copy(source.toPath(), destination, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException copyError) {
// Diagnose path, permissions, volume, and disk-space problems separately.
throw copyError;
}
Do not swallow either exception. A report that says only “screenshot failed” hides whether the browser, API type, or filesystem was responsible.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Or skip the browser setup
For a service that captures a URL outside your Selenium session, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or a PDF. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result.
Use the API documentation at https://screenshotneo.com/docs/ for the complete option list. A minimal call is:
Best Value
- 【Expansive Display】The 14 Non-touch display offers clear and vibrant visuals, and anti-glare coating, perfect for both work and entertainment.
- Designed for mobility with a slim 0.71-inch profile and lightweight 3.24 lb chassis, making it easy to carry between home, office, school
- 【Versatile Connectivity】Stay connected with multiple ports including USB 3.0 Type-C, USB 3.0 Type-A, HDMI, and a headphone/mic combo jack, along with Wi-Fi and Bluetooth for seamless wireless networking.
- One Year Microsoft 365
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Equivalent Python:
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)
Equivalent Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Relevant controls include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets or any viewport, retina scale, PDF paper size/margins/landscape/page ranges, custom CSS and JavaScript, pre-capture clicks, hidden selectors, waits for a selector/delay/network idle, ad/tracker/request/resource blocking, custom headers/cookies/user agent/Authorization, timezone and geolocation, transparent backgrounds, image resizing, chosen cache TTL, signed links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, an OpenAPI specification, and familiar parameter names for easier migration. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
Every plan includes every feature: 1,000 shots per month free with no card; Starter is $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000. Yearly billing gives two months free. Sign up for the free 1,000-screenshot plan.
Practical checklist
- Confirm the object in
driversupportsTakesScreenshot. - Import Selenium’s
OutputTypeandTakesScreenshot. - Capture with
OutputType.FILE,BYTES, orBASE64according to your pipeline. - If using
FILE, copy immediately to a created, writable destination. - Log the absolute destination path and preserve the full exception.
- Separate browser capture failures from filesystem copy failures.
- Qualify element, viewport, and full-page expectations for the actual browser and driver.
Frequently Asked Questions
Does `OutputType.FILE` save directly to my chosen filename?
No. It returns Selenium’s temporary file. Your code must copy it to the chosen destination.
Can I use `OutputType.BYTES` instead of a temporary file?
Yes. It returns a `byte[]`; your application then decides how to write or upload those bytes.
Why does the same relative path work locally but fail in CI?
Relative paths are resolved from the process working directory, which may differ between an IDE, build tool, and CI runner. Log the absolute path and verify directory permissions.
Is a generic Selenium screenshot always full page?
No. Screenshot extent depends on the API and implementation. Verify the browser-specific support before relying on full-page output.
Free tools Windows power users keep installed
One-click scans. No signup required.
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.

