Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use a readable test label followed by a freshly generated UUID, then save the file with a .png extension. For example, checkout-550e8400-e29b-41d4-a716-446655440000.png identifies the test while avoiding the overwrites that occur when every run writes to screenshot.png. Create the destination directory first and check that Selenium actually saved the file.
Python: save a uniquely named screenshot
Python’s Selenium WebDriver API documents save_screenshot(filename) and get_screenshot_as_file(filename) as saving the current window to a PNG file. The API page identifies Selenium 4.49.0; its save methods return False if an I/O error occurs and recommend providing a full path. Generate the name when the capture happens, not once at module import or test-suite startup.
from pathlib import Path
from uuid import uuid4
output_dir = Path("artifacts/screenshots")
output_dir.mkdir(parents=True, exist_ok=True)
filename = f"checkout-{uuid4()}.png"
path = output_dir / filename
saved = driver.save_screenshot(str(path))
if not saved:
raise OSError(f"Could not save screenshot to {path}")
print(f"Screenshot saved to {path}")
This assumes that driver is an initialized Selenium WebDriver. The directory is created recursively if it does not exist, and exist_ok=True makes repeated setup safe. The label checkout is an example; use a short test or page identifier that helps you recognize the artifact.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →The Python UUID documentation for Python 3.14.7 describes uuid4() as generating a random UUID using a cryptographically secure method. The resulting identifier is a practical filename suffix for avoiding accidental collisions in ordinary test-artifact workflows. The cited documentation does not quantify collision probabilities, so do not treat it as an absolute guarantee or a replacement for checking file-write success.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Alternative Python save method
If you prefer the method name that explicitly says it saves to a file, use get_screenshot_as_file with the same generated path and check its boolean result:
saved = driver.get_screenshot_as_file(str(path))
if not saved:
raise OSError(f"Could not save screenshot to {path}")
Both methods in the documented Python API save PNG screenshots. Keep the filename’s .png extension, use an appropriate path, and ensure the process can write to its parent directory. See the Selenium Python WebDriver API and Python UUID documentation.
Java: generate a UUID filename and copy the screenshot
In Java, build a destination path with UUID.randomUUID(), obtain the screenshot as a file through Selenium’s TakesScreenshot interface, and copy it into the artifacts directory. The Java API documents UUID.randomUUID() as producing a type 4 pseudo-random UUID using a cryptographically strong pseudo-random number generator.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
static Path saveScreenshot(WebDriver driver) throws IOException {
Path outputDir = Path.of("artifacts", "screenshots");
Files.createDirectories(outputDir);
Path path = outputDir.resolve("checkout-" + UUID.randomUUID() + ".png");
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(screenshot.toPath(), path);
return path;
}
Call saveScreenshot(driver) after creating the WebDriver and navigating to the page you want to capture. The helper creates the output directory before copying and returns the destination path. The Selenium Java TakesScreenshot API documents screenshot capture and supported output forms; the Oracle Java SE 26 UUID documentation describes the UUID generator. This code combines those documented building blocks; it does not imply a browser test or a guarantee about every Selenium driver implementation.
Choose a filename pattern that fits the test run
A good name balances collision resistance, readability, sortability, length, and whether separate processes write into the same directory. The UUID choice and naming combinations below are implementation guidance; the cited APIs document the filename and UUID capabilities rather than prescribing a naming convention.
| Pattern | Example | Useful when | Trade-off |
|---|---|---|---|
| UUID only | 550e8400-e29b-41d4-a716-446655440000.png |
You need a short, simple way to distinguish captures. | Harder to identify by inspection because the name carries no test context. |
| Timestamp only | checkout-20260929T211800Z.png |
You want filenames that sort by capture time and are easy to scan. | Two captures can share the same timestamp resolution; coordinated or inaccurate clocks can also undermine time-based naming. |
| Label, timestamp, and UUID | checkout-20260929T211800Z-550e8400-e29b-41d4-a716-446655440000.png |
You need test context, a time cue, and a highly collision-resistant identifier in shared artifacts. | Longer names require sensible label length and filesystem-safe characters. |
| Run or case identifier plus UUID | run42-checkout-550e8400-e29b-41d4-a716-446655440000.png |
Your CI system groups output by run and you want a recognizable case name as well. | A run or worker identifier alone does not guarantee unique filenames. |
When to add a timestamp
A timestamp can help humans sort files or see roughly when a capture occurred, but it should not be the only uniqueness mechanism when concurrent workers may write to one directory. Timestamp precision, clock behavior, and the number of captures sharing a time interval determine whether names could collide. Pair the timestamp with a UUID when both ordering and collision resistance matter.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Keep labels useful and safe
- Use a stable, short test or case label rather than a full URL or a long description.
- Sanitize labels for the filesystem receiving the artifact. Avoid path separators and characters that the target operating system or artifact service rejects.
- Do not put passwords, access tokens, personal data, or other secrets in filenames; artifact names can appear in logs and build interfaces.
- If CI already stores screenshots in per-run or per-worker directories, include a case label and UUID where separate cases might still share a destination.
- Keep the extension aligned with the actual output. The Python Selenium methods above save PNG files and the documented API asks for a filename ending in
.png.
Parallel workers, directories, and write safety
A unique filename solves only one part of artifact handling. Workers can still fail to save if the directory does not exist, is read-only, or is unavailable in the process’s current working directory. Relative paths such as artifacts/screenshots are resolved from that working directory, which can differ between a local run and a CI job.
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 reinstall- Choose an explicit artifact root. In CI, use the workspace or artifact directory your runner provides, and pass a full path to Selenium where appropriate.
- Create directories before capture. Python’s
mkdir(parents=True, exist_ok=True)and Java’sFiles.createDirectorieshandle missing parent directories. - Use a UUID even with worker names. Worker labels help identify where a file came from; they are not sufficient if the same worker captures the same test more than once.
- Check the outcome. Python returns a boolean from its documented save methods. Java’s file-copy operation reports I/O failures by throwing an exception.
- Keep artifact collection separate from naming. Naming does not configure your CI system to upload or retain the resulting files.
UUIDs make accidental clashes highly unlikely in ordinary artifact workflows, but that statement is practical inference from random UUID generation—not a collision-rate figure established by the API documentation. Handle write failures and keep the destination organized even when names are unique.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting screenshot filenames and saves
The second screenshot overwrites the first
The code is probably reusing a constant name, such as screenshot.png, or generating the name only once and reusing it. Build the filename for each capture with uuid4() or UUID.randomUUID(). If you need to diagnose which test produced the file, add a sanitized test label before the UUID.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
The parent directory does not exist
Creating a file does not automatically create its parent directories in these examples. Run output_dir.mkdir(parents=True, exist_ok=True) in Python or Files.createDirectories(outputDir) in Java before saving or copying.
Python returns False
The Selenium Python API documents a false return on an I/O error. Check that the path is valid, its parent directory exists, and the running process has write access. Use a full path if the current working directory is uncertain, then fail visibly rather than silently treating the missing image as a successful test artifact.
Java reports an I/O exception
Files.copy can fail if the destination directory is absent, the destination cannot be written, or a file already occupies the target path. Create the directory before copying and inspect the exception’s path and cause. A fresh UUID filename avoids normal reuse of the same destination, but it does not correct permissions or storage failures.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
The filename is hard to read or too long
Use a compact label and omit details already present in the test report or directory structure. Include a timestamp only if time-based sorting is useful, and retain the UUID suffix where concurrent or repeated captures are possible. Keep sensitive values out of names.
The screenshot file is not a PNG
The Python methods discussed here save PNG output; use the .png suffix. A filename suffix does not convert one image format into another. If another screenshot path or tool is used, confirm its returned format before choosing a different extension.
Or skip the browser setup
If you need a website capture without setting up Selenium and a browser, ScreenshotNeo accepts a URL in one GET request and returns a screenshot or PDF. The example saves a WebP response; use your own API key and replace the target URL as needed.
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 request options and response details. ScreenshotNeo removes cookie or consent banners, newsletter popups, and chat widgets before capture; those steps can each be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
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.

