Call Selenide.screenshot("my_file_name") after the page is in the state you want to capture. Selenide writes my_file_name.png and returns the screenshot file URL. Depending on configuration, it can also save page source. For assertions or APIs that need the image in memory, use Selenide.screenshot(OutputType.BASE64) (or another supported output type).
The three ways to capture a Selenide screenshot
Selenide supports three distinct workflows. Pick the one that matches where the image must go:
| Goal | Call or configuration | Result |
|---|---|---|
| Save a named artifact | Selenide.screenshot("my_file_name") |
A PNG named my_file_name.png; page source may be saved too. |
| Use image data in test code | Selenide.screenshot(OutputType.BASE64) or another documented OutputType |
Base64, bytes, or a temporary file, depending on the output type. |
| Capture automatically | Leave screenshot capture enabled and use Selenide/framework integrations | Failure screenshots by default, plus optional successful-test and non-Selenide-assertion capture. |
The examples below describe the current Selenide 7.18.2 API. Screenshot behavior and configuration names are version-sensitive, so check the version used by your build when diagnosing a difference.
Save a named PNG
Import the static method and call it once the browser has rendered the state you want to preserve:
Recommended Free Tools
import static com.codeborne.selenide.Selenide.screenshot;
String pngFileName = screenshot("my_file_name");
The call creates my_file_name.png. The returned value is the URL of that file, which is useful when a test report or logger needs to link to the artifact. If WebDriver cannot create a screenshot, the method returns null rather than a usable file URL.
What else is written?
Selenide can save the page source alongside the PNG. The source file is created only when Configuration.savePageSource is true; the PNG itself is created independently. In Chromium, setting Configuration.savePageSourceWithResources enables an MHTML capture with embedded resources instead of plain HTML. The MHTML option is available in the 7.18.x line; Selenide 7.18.0 documents an HTML fallback when MHTML is unavailable or the capture fails.
Return the screenshot to Java code
A named file is convenient for reports, but image-processing code, an upload client, or a custom assertion may need the image value directly. Use the overload that accepts an OutputType:
import static com.codeborne.selenide.Selenide.screenshot;
import org.openqa.selenium.OutputType;
String base64 = screenshot(OutputType.BASE64);
OutputType.BASE64 returns the encoded image. Decode it only when you need bytes:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #2
import java.util.Base64;
import static com.codeborne.selenide.Selenide.screenshot;
import org.openqa.selenium.OutputType;
String base64 = screenshot(OutputType.BASE64);
if (base64 == null) {
throw new IllegalStateException("WebDriver did not provide a screenshot");
}
byte[] pngBytes = Base64.getDecoder().decode(base64);
The same overload can return raw bytes or a temporary file when you select the corresponding documented output type. Treat a null return as a driver limitation or capture failure and handle it before attempting to decode or upload the value.
Put artifacts in a predictable report folder
For Gradle projects, the current API lists build/reports/tests as the default reportsFolder. Set a project-specific directory in code:
import com.codeborne.selenide.Configuration;
Configuration.reportsFolder = "test-result/reports";
Or set the same location as a JVM property when launching the tests:
./gradlew test -Dselenide.reportsFolder=test-result/reports
The current property is selenide.reportsFolder. Older Selenide 4.x documentation used selenide.reports; using that legacy name with a current release will not select the folder you expect.
Windows 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 reinstallOutdated 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 matchSet the folder before the first screenshot is taken. Use a workspace directory that your CI job preserves as an artifact; otherwise the test may pass while the image disappears when the runner is cleaned up.
Capture failures automatically
Selenide’s screenshots configuration is true by default. When a Selenide check such as shouldBe fails, Selenide captures a screenshot and page source so the failure report contains the browser state at the point of failure. This is separate from an explicit call to screenshot().
Failed Selenide checks
Keep automatic capture enabled when debugging intermittent UI failures. The generated files use the test/report context rather than the explicit name you supply to screenshot(String). If you need a stable filename for a particular checkpoint, add an explicit named call as well.
Successful tests
JUnit 4 and JUnit 5 integrations can capture screenshots for successful tests when configured. TestNG uses its Selenide listener for the same purpose. The exact registration belongs in your test framework setup; do not assume that enabling failure screenshots also captures every passing test.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #4
Assertions outside Selenide
A failure from a plain JUnit or TestNG assertion is not the same event as a failed Selenide condition. Use the framework integration documented for your runner if you want screenshots for those assertions, or call screenshot() immediately before the assertion when a checkpoint is more useful than a failure hook.
A complete checkpoint example
This example opens a page, waits for a visible result through a Selenide condition, writes a named PNG, and keeps the returned file URL available to the test report:
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.Selenide.screenshot;
import org.junit.jupiter.api.Test;
class CheckoutTest {
@Test
void captureCheckoutState() {
open("https://example.test/checkout");
$("[data-testid='order-summary']").shouldBe(visible);
String artifact = screenshot("checkout-ready");
if (artifact == null) {
throw new IllegalStateException("Screenshot was not created");
}
}
}
Replace the URL and selector with values from your application. The important ordering is: navigate, wait for the state that matters, then capture. Taking the image before the condition completes can preserve a loading spinner or an empty shell instead of the page your test is checking.
Page source, resources, and browser limitations
- PNG is the image artifact. A named screenshot always targets PNG output.
- HTML is optional. Enable
Configuration.savePageSourcewhen a DOM snapshot helps diagnose the failure. - MHTML is Chromium-specific. With
Configuration.savePageSourceWithResources, configured Chromium runs attempt to save page source with embedded resources. If that capture is unsupported or fails, Selenide falls back to HTML. - Drivers can decline screenshots. The named method returns
nullwhen it cannot create the file, and the output-type overload can also returnnullwhen WebDriver does not support screenshots.
Keep HTML or MHTML capture intentional. Embedded resources can make an artifact substantially more useful offline, but they also create larger files and may contain sensitive page data.
Best Value
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No file appears | The call returned null, or the report directory is not preserved. |
Check the return value, verify the active WebDriver supports screenshots, and archive the configured reports folder in CI. |
| PNG exists but no HTML file | Configuration.savePageSource is false. |
Set it to true before capture. |
| Expected MHTML, received HTML | The browser/driver could not provide MHTML, or the MHTML operation failed. | Use Chromium with savePageSourceWithResources enabled; accept the documented HTML fallback when MHTML is unavailable. |
| Screenshot shows an incomplete page | Capture ran before asynchronous content finished. | Wait for a meaningful element or state with a Selenide condition, then call screenshot(). |
| Files are in an unexpected directory | A different reports-folder setting is active, or the old 4.x property name was used. | Set Configuration.reportsFolder or -Dselenide.reportsFolder=... and remove selenide.reports. |
| Passing tests have no screenshots | Failure capture is enabled, but successful-test integration is not configured. | Configure the JUnit 4/JUnit 5 integration or the TestNG listener for your runner. |
| Base64 decoding fails | The output is null or was treated as bytes without decoding. |
Check for null, then decode the Base64 string with Base64.getDecoder(). |
| Screenshot captures the wrong state | The browser is on a different step, tab, or viewport than expected. | Switch to the intended browser context, assert the target element, and capture immediately after that assertion. |
Performance and reliability choices
- Capture only useful checkpoints. A screenshot after every command creates noise and slows suites more than a small set of state-based checkpoints.
- Prefer failure hooks for broad coverage. Automatic failure capture gives context without adding calls to every test. Add named captures where a particular business state must be reviewed.
- Separate image and source needs. Keep page-source saving off when PNGs are sufficient; enable it for investigations where DOM or resource context matters.
- Make artifact paths deterministic. Configure one report directory and preserve it in CI so links remain valid across runs.
- Guard programmatic output. A null result should fail with a clear diagnostic rather than producing a later, misleading decoding or upload error.
- Capture after a stable condition. Waiting for a selector that represents completed content is more reliable than sleeping for an arbitrary duration.
Or skip the browser setup
If you need a screenshot service rather than a WebDriver session, ScreenshotNeo returns an image or PDF from one HTTP request. 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 or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the result with X-Page-Verdict and X-Billed headers. It also provides an MCP server for Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools.
Use the API documentation at https://screenshotneo.com/docs/ for authentication and all options. A minimal cURL request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
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(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
Beyond a basic capture, ScreenshotNeo supports full-page screenshots with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets, arbitrary viewports, retina scale, PDF paper sizes and page ranges, HTML/CSS-to-image, custom JavaScript and CSS, clicks, selector waits, delays, network-idle waits, ad/tracker/request blocking, custom headers, cookies, user agents and Authorization, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed image 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.
| Plan | Included screenshots | Price |
|---|---|---|
| Free | 1,000 per month | $0; no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
All features are available on every plan, and yearly billing gives two months free. Create a free ScreenshotNeo account to get 1,000 screenshots each month without adding a card.
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 →Frequently Asked Questions
Can I keep a screenshot in memory without writing a report file?
Yes. Use the OutputType overload, such as OutputType.BASE64, and pass the returned value to your own assertion, storage, or upload code.
When is MHTML preferable to plain page source?
MHTML is useful when you need a Chromium page snapshot with embedded resources for offline inspection. Enable it deliberately because a plain HTML file is smaller and is the documented fallback when MHTML capture is unavailable.
Why would a team use both Selenide and an HTTP screenshot API?
Selenide is suited to screenshots taken during an existing browser test. An HTTP API is useful when you need repeatable URL captures without starting WebDriver, or when an AI agent must request screenshots through MCP.
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

