To capture the current browser view in Selenium Java, call getScreenshotAs on a driver that supports TakesScreenshot. Use OutputType.FILE for a temporary image file, then copy it to a permanent destination before the JVM exits. Selenium also supports raw bytes and Base64 output. The exact capture boundaries depend on the driver implementation, so the basic call should not be treated as a guaranteed full-page screenshot.
Capture and save a Selenium screenshot
Selenium’s Java entry point is the TakesScreenshot interface. After navigating to the page and waiting until it is in the state you want to record, request a screenshot from the driver and save the result:
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 class ScreenshotHelper {
public static void saveScreenshot(WebDriver driver, String destination)
throws IOException {
File temporaryScreenshot =
((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(temporaryScreenshot, new File(destination));
}
}
This method expects an already-created and navigated WebDriver. The cast works only when the concrete driver supports TakesScreenshot. The returned File is temporary: Selenium documents that it may be deleted when the JVM exits, so copy it to the destination you need rather than relying on the temporary path. The official Selenium example uses Apache Commons IO’s FileUtils.copyFile for that step. See the Selenium TakesScreenshot API, OutputType API, and Selenium’s official usage example.
The method declares IOException because copying a file can fail, for example if the destination directory does not exist or cannot be written. Create the directory first or pass a path in a writable location. If your project does not already include Apache Commons IO, add that dependency or use Java’s Files.copy instead; Selenium’s screenshot API itself returns the temporary file, it does not choose or create your permanent destination.
#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
Call it after navigation and readiness checks
A screenshot records the state the browser has reached at the time of the call. In a test, the useful sequence is: open the page, wait for a meaningful page condition, and then capture. A fixed sleep may work for a deliberately static page, but it can produce intermittent results when network or rendering time varies. Prefer the synchronization condition appropriate to the test, such as waiting for the page element whose rendered state matters.
// driver has been created and configured elsewhere
driver.get("https://example.com");
// Wait for the relevant page state in your test before capturing.
ScreenshotHelper.saveScreenshot(driver, "./screenshot.png");
The URL and readiness condition are application-specific. This fragment is not a complete browser-launch example because driver setup depends on your browser and test environment; the screenshot call itself is the same once you have a configured WebDriver.
Choose the output type that fits your code
OutputType offers three forms. Pick the one that matches what happens next in your test or application; there is no universally best output type documented by Selenium.
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.
| Output type | Result | Use it when | Important handling |
|---|---|---|---|
OutputType.FILE |
A temporary File |
You want to copy or move the image to disk. | Copy it to a persistent path before the JVM exits. |
OutputType.BYTES |
A raw byte[] |
You need to process or store the image in memory. | Write the bytes yourself if you want a file. |
OutputType.BASE64 |
A Base64-encoded String |
The next step consumes an encoded string. | Decode it before treating it as image bytes. |
For example, to save the byte-array form with standard Java file APIs:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchimport 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;
public static void saveScreenshotBytes(WebDriver driver, Path destination)
throws IOException {
byte[] image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
Files.write(destination, image);
}
For Base64 output, the value is encoded text, not a normal image path. Decode it before writing bytes to a file:
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public static void saveScreenshotBase64(WebDriver driver, Path destination)
throws Exception {
String encoded =
((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
Files.write(destination, Base64.getDecoder().decode(encoded));
}
In production code, use the narrow exception types appropriate to your method rather than copying the broad throws Exception declaration in this short illustration.
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.
Capture an element instead of the browser context
If the test needs a screenshot of one element, obtain the target WebElement and use its screenshot capability rather than capturing through the driver. Selenium documents screenshot support through both WebDriver and WebElement in the TakesScreenshot API reference.
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.WebElement;
public static void saveElementScreenshot(WebElement element, String destination)
throws IOException {
File temporaryScreenshot =
((TakesScreenshot) element).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(temporaryScreenshot, new File(destination));
}
Find the element and wait until it is in the intended state before calling this helper. The captured target is the element rather than the whole browsing context. Do not assume identical boundaries across browser drivers: Selenium describes behavior from implementations that do not conform to the W3C specification as best effort. Check the behavior of the specific driver used in your test when exact cropping matters.
Recommended Free Tools
Know what the basic driver call captures
driver.getScreenshotAs(...) is not a portable promise to stitch an entire long page from top to bottom. The API describes screenshot behavior in terms of the implementation’s conformance; it does not guarantee cross-browser full-page capture for this basic call. If your test requires a full-page image, verify the relevant driver’s documented behavior and test it in the same browser and execution mode used by your suite.
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.
Also distinguish a screenshot from evidence that the page is correct. The image only records the browser’s rendered state. A blank or partially loaded image may mean the capture happened before the application was ready, or that the page itself did not render as expected. Make the test wait for the relevant condition and assert the page state separately.
Handle driver support and failures
Several browser drivers and remote-driver classes implement TakesScreenshot, but support can vary. The API may throw UnsupportedOperationException when the implementation does not support screenshots, or WebDriverException when capture fails. Consult the Java API contract rather than assuming every object typed as WebDriver can produce an image.
| Symptom | Likely cause | What to check |
|---|---|---|
ClassCastException at the cast |
The concrete driver does not implement TakesScreenshot. |
Confirm the driver class and its screenshot support; do not cast blindly. |
UnsupportedOperationException |
The implementation does not support the requested screenshot operation. | Check the driver’s capabilities and whether element capture is supported there. |
WebDriverException |
The browser or remote session failed to complete capture. | Check that the session is alive, the browser is responsive, and the driver supports the operation. |
IOException while saving |
The temporary capture may have succeeded, but copying or writing failed. | Check the destination path, parent directory, filesystem permissions, and available storage. |
| Image is blank or shows an incomplete state | The capture may have occurred before the page reached the intended state. | Wait for the page condition relevant to the test, then capture again. |
| Image omits content lower on a long page | The basic driver screenshot is not guaranteed to be a full-page capture. | Verify the specific implementation’s behavior; do not infer full-page support from the interface. |
Keep screenshot handling reliable in a test suite
- Use a deliberate destination. Relative paths such as
./screenshot.pngare resolved from the test process’s working directory, which may differ between an IDE, a build tool, and CI. Prefer a known artifact directory when screenshots need to be collected. - Give each capture a distinct name. A fixed filename can be overwritten by later tests or parallel workers. Include an identifier that distinguishes the test and run, while avoiding sensitive data in filenames.
- Capture at the right point. A screenshot taken after a failed assertion can help with diagnosis, but also capture before cleanup if the browser session is about to close. Decide which failures warrant an artifact so routine passing tests do not create unnecessary files.
- Preserve only what you need. Screenshot files can contain account details, personal information, or test data visible in the page. Restrict access to artifacts and apply the retention rules used for your test results.
- Keep cleanup separate. The screenshot call does not replace normal driver lifecycle management. Quit the driver after your capture and any other required test work, typically in a
finallyblock or test-framework teardown.
Or skip the browser setup
If you need an image of a publicly reachable page rather than a screenshot produced inside your Selenium test, ScreenshotNeo offers a single GET request through its website screenshot API. For the API parameters and available options, see the ScreenshotNeo documentation.
Best Value
- Efficient Intel Processor: Powered by Intel Celeron 5205U dual-core two-thread processor with a fixed 1.9GHz base frequency, 2MB Intel Smart Cache and advanced 14nm Comet Lake lithography. Integrated Intel UHD Graphics for 10th Gen Intel Processors delivers stable daily performance. It handles daily office tasks, web browsing, video streaming and light multitasking smoothly while featuring ultra-low power consumption for extended use.
- Fast Response Large Storage:Equipped with 12GB high-speed RAM to accelerate program loading and enable seamless multitasking. Built-in 256GB solid-state drive provides rapid boot and application launch speeds, offering ample storage space for your documents, software, photos and videos. Run daily productivity and multimedia applications without lag or slowdowns.
- 15.6" FHD IPS Eye-Care Display:This laptop features a 15.6-inch Full HD IPS panel with native 1920×1080 resolution and classic 16:9 widescreen ratio. Designed with slim 5mm ultra-narrow bezels, anti-glare coating and blue light filtering eye protection, it effectively reduces eye strain during long hours of studying, streaming or working, delivering vivid, immersive visual experiences. effectively reduce blue light and eye strain, bringing you immersive visual experience for watching videos and studying.
- Pre‑Installed Windows 11: Ready to Use Comes with a genuine Windows 11 system pre‑loaded, offering a clean, intuitive interface and broad software compatibility. Open the box, power on, and you're all set for school assignments, business reports, or daily computing needs.
- Rich Ports & Long Lasting Battery Life:Built-in 38Wh rechargeable battery and dual stereo speakers. Support Bluetooth 4.2 & 2.4G/5G dual-band WiFi for fast wireless connection. Equipped with Type-C, HDMI, 3.5mm audio jack, dual USB 3.0, Micro TF slot and DC charging port, meet your daily external device connection and office expansion needs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie and consent banners are accepted like a visitor and removed before capture; newsletter popups and chat widgets are also removed. Each step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. The response identifies the page verdict and billing status in
X-Page-VerdictandX-Billedheaders. - An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for AI agents, including Claude, Cursor, and other MCP clients. - The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month—no card required.
Which method should you use?
For a Java browser-automation test, use Selenium’s TakesScreenshot: choose FILE when you want to copy the temporary result to disk, BYTES for in-memory work, or BASE64 when the next component expects encoded text. Use element capture when the target is a specific element, and verify driver behavior where precise capture boundaries or full-page output matter. Use a screenshot API for a remote URL capture workflow that does not require driving your own Selenium browser session.
Frequently Asked Questions
Does saving a Selenium screenshot automatically close the browser?
No. Capture and browser-session cleanup are separate operations; close the session through your normal test teardown after the work that needs the browser is complete.
Can I use the same screenshot output choice for a file and an in-memory workflow?
The API offers separate FILE, BYTES, and BASE64 forms. Choose the result format that matches the consumer, then copy, write, or decode it as needed.
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.

