What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For a Java Selenium test, capture a browser image through Selenium’s TakesScreenshot interface, then copy the temporary file to your report directory. The same interface can capture a driver or a screenshot-capable element, and Selenium also supports Base64 output. Krypton’s available user manual describes a separate error-capture setting, ErrorCaptureAs, for choosing an image or HTML capture; it does not document a Java screenshot hook. Treat Krypton as the test layer and Selenium as the capture API unless your project’s own Krypton integration supplies additional code.
What the Krypton-and-Selenium boundary means
The standard Java call is ((TakesScreenshot) driver).getScreenshotAs(...). Selenium’s API describes TakesScreenshot as indicating that a driver or HTML element can capture a screenshot and store it in different ways (Selenium TakesScreenshot API). Krypton’s manual says its Selenium-based test driver can capture an image or HTML when an error occurs by setting ErrorCaptureAs (Krypton user manual). That manual does not specify a Java method, image format, filename, or compatibility with current Selenium releases, so the code below is a Selenium implementation you can call from a Krypton test step or failure handler rather than a claimed Krypton API.
Prerequisites and project setup
- A Java project with Selenium WebDriver and a browser driver configured.
- A live
WebDriverinstance at the moment you capture. Capture beforedriver.quit(). - A writable artifact or report directory, such as
target/screenshots. - A driver implementation that supports screenshots. Selenium documents that unsupported implementations can throw
UnsupportedOperationException, and other failures can surface asWebDriverException.
Use the Selenium version already approved by your build. The API contract is more important here than a particular version number; the cited Krypton manual is older and should not be read as a current browser-support matrix.
Save a full browser screenshot to a file
OutputType.FILE asks Selenium for a temporary image file. Copy it to a destination you control so the artifact survives driver cleanup and test-runner housekeeping.
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
static void saveScreenshot(WebDriver driver, Path destination) throws IOException {
File screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
Files.createDirectories(destination.getParent());
Files.copy(screenshot.toPath(), destination);
}
Example use:
Path artifact = Path.of("target", "screenshots", "checkout-home.png");
saveScreenshot(driver, artifact);
Files.copy intentionally fails if the destination already exists. That prevents an earlier run from being silently overwritten. If replacement is what you want, pass StandardCopyOption.REPLACE_EXISTING; for parallel tests, include a test name, timestamp, or UUID in each filename instead.
Capture a screenshot when a test fails
Take the image inside the failure path while the page and its browsing context still exist, then rethrow the original failure. Catching Throwable also covers assertion errors; if your test policy excludes fatal JVM errors, catch the assertion and exception types your runner uses instead.
try {
// test actions and assertions
} catch (Throwable failure) {
try {
saveScreenshot(driver,
Path.of("target", "screenshots", "failure.png"));
} catch (IOException | RuntimeException captureFailure) {
failure.addSuppressed(captureFailure);
}
throw failure;
} finally {
driver.quit();
}
The nested handling keeps a failed screenshot from hiding the real test failure. In a parallel suite, create a per-test directory before writing. If navigation itself failed, the screenshot may show a browser error page, a partially rendered document, or a blank page; that is still useful diagnostic evidence.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Return Base64 instead of writing a file
Selenium documents Base64 as another output form. It is useful when a test report, message, or remote artifact service accepts text.
Rank #2
String imageBase64 = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BASE64);
Base64 increases the in-memory representation compared with binary bytes, so write a file or use OutputType.BYTES when your reporting system accepts binary data. Do not log the entire Base64 value in normal CI output; attach it as an artifact.
Capture one element rather than the whole page
A screenshot-capable WebElement can be cast to TakesScreenshot. This is appropriate for a chart, invoice, or component whose bounds matter more than the surrounding browser window.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
WebElement invoice = driver.findElement(By.cssSelector(".invoice"));
File elementFile = ((TakesScreenshot) invoice)
.getScreenshotAs(OutputType.FILE);
Files.copy(elementFile.toPath(),
Path.of("target", "screenshots", "invoice.png"));
Element capture behavior depends on driver support and WebDriver conformance. Selenium describes non-conformant implementations as best effort, so do not assume identical cropping across browsers. Wait for the element to be present and visible before capture; otherwise you can get an exception or an incomplete image.
Full-page expectations and browser differences
The ordinary driver screenshot represents the current browsing context. Whether it includes only the viewport or a longer page depends on the browser-driver implementation and its support for the relevant WebDriver behavior. Selenium’s usage documentation shows driver and element examples for the current context (Selenium WebDriver browser documentation), while the API warns that unsupported or non-conformant implementations may vary.
- For a reliable viewport image, set the window size or use a device profile before navigation.
- For a long page, verify the result on each browser in your matrix rather than assuming a stitched full-page image.
- Lazy-loaded content may not exist until you scroll it into view; perform the required scrolling and waits before capture.
- Animations, caret blinking, fonts, and network timing can make two otherwise identical captures differ.
Connecting the capture to Krypton
If your Krypton test run exposes a Java extension point, call saveScreenshot(driver, destination) from that hook and pass the same driver Krypton is using. If it only exposes the documented ErrorCaptureAs configuration, configure it according to your installed Krypton version and use its generated artifact; do not assume that setting invokes the Java method above. The manual establishes image-versus-HTML selection for the page where an error occurred, but not the output filename, image encoding, or a modern Selenium integration contract.
Keep these concerns separate in your test design:
| Concern | Responsible layer | What you control |
|---|---|---|
| Browser interaction and current page | Selenium WebDriver | Navigation, waits, viewport, cookies, and the capture call |
| Java image representation | TakesScreenshot |
File, Base64, or bytes output and destination handling |
| Spreadsheet-driven execution and error policy | Krypton (per its manual) | ErrorCaptureAs choice and the framework’s own artifact flow |
Automatic failure screenshots with Selenide
If the project is already using Selenide rather than direct WebDriver calls, its documentation describes automatic screenshots on test failures, a configurable reports folder, Java hooks for JUnit and TestNG, and direct calls such as Selenide.screenshot(...) (Selenide screenshots documentation). This is a separate framework path, not evidence of a Krypton integration. Choose it when your suite already uses Selenide’s lifecycle; otherwise the small TakesScreenshot helper gives you explicit control.
Common errors and fixes
ClassCastException when casting the driver
Cause: the active driver implementation does not implement TakesScreenshot. Fix: use a supported browser driver, check the concrete driver in your Selenium version, and fail with a clear diagnostic rather than assuming every remote implementation supports images.
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 reinstallUnsupportedOperationException
Cause: the underlying driver advertises no screenshot operation. Fix: switch to a conformant driver or enable its screenshot capability; do not silently create an empty file.
Rank #4
WebDriverException during capture
Cause: the session has crashed, the browser is unreachable, or the current implementation rejected the command. Fix: preserve the original test error, record the capture exception as suppressed, and inspect driver and browser logs.
NoSuchElementException for an element screenshot
Cause: the element has not rendered, the selector changed, or the frame/window is wrong. Fix: switch to the correct window or frame and use an explicit wait for the element before casting it.
AccessDeniedException or missing artifact
Cause: the destination directory does not exist or the CI worker cannot write there. Fix: create parent directories, use a workspace-relative path, and publish that directory as a CI artifact.
Recommended Free Tools
Blank or incomplete image
Cause: capture happened before navigation, fonts, images, or asynchronous content finished. Fix: wait for a meaningful page condition, scroll lazy content if needed, and capture before teardown. A blank page can also be the browser’s response to a failed navigation and is evidence of that failure rather than a file-copy problem.
Best Value
Reliability and artifact practices
- Give every test a unique filename to prevent parallel workers overwriting one another.
- Store the URL, browser name, viewport, test name, and timestamp beside the image so a reviewer can reproduce the state.
- Capture at the failure site, not in a later cleanup method after the driver has been closed.
- Keep image size under control by capturing an element or viewport when a full page is unnecessary.
- Decide whether an existing file should fail, replace, or receive a unique suffix; make that policy explicit.
- Publish screenshots only when a test fails if storage is limited, while retaining a switch for always-on diagnostic captures.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. 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. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—let Claude, Cursor, or another MCP client request captures without you managing a browser driver. Every plan includes the features, from element selectors and full-page lazy-image loading to custom CSS/JavaScript, waits, headers, cookies, geolocation, PDFs, caching, signed links, async webhooks, bulk capture, and a usage API.
One request returns an image or PDF:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for output and option details. The same call in Python is:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
And in 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}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const image = Buffer.from(await res.arrayBuffer());
await require('node:fs').promises.writeFile('shot.webp', image);
The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free. Sign up for the free ScreenshotNeo plan to try the one-call approach without a card.
Choosing the right approach
- Use direct Selenium when the screenshot must reflect the exact authenticated browser state, window, frame, or test moment.
- Use Krypton’s error setting when your installed Krypton workflow already manages failure artifacts and you do not need a Java-level destination.
- Use Selenide when its automatic failure reporting is already part of the Java test stack.
- Use ScreenshotNeo when you need a service call, cleaned public-page images, PDF output, bulk URLs, or AI-agent access without provisioning a browser.
Frequently Asked Questions
How do I take a screenshot in Selenium Java?
Cast the driver to TakesScreenshot and call getScreenshotAs(OutputType.FILE), then copy the returned temporary file to your artifact directory.
Can Selenium capture only an element?
Yes. A screenshot-capable WebElement can also be cast to TakesScreenshot; the exact result depends on driver support.
Does Krypton provide a Java screenshot method?
The available Krypton manual documents the ErrorCaptureAs image-or-HTML setting but does not document a Java screenshot API. Use Selenium’s API unless your project integration supplies a hook.
Why is my screenshot missing after the test?
Capture before driver.quit(), create the destination directory, and publish the directory as a CI artifact.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesQuick 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.

