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.
Use Selenium’s await driver.takeScreenshot() to capture a PNG, then write the returned Base64 string to disk with Node’s fs/promises API and the base64 encoding. For test outcomes, use your test runner’s reporter or save a deliberate JSON summary; Selenium captures browser state, but it does not provide a test-results API. This guide covers both artifacts, safe filenames, cleanup, and CI handling.
What you need before you start
The examples use the Selenium JavaScript binding, the selenium-webdriver package, and Node.js. The Selenium JavaScript API documentation currently specifies Node.js 22 or newer; check its current requirements and your installed package before setting up a new environment: Selenium WebDriver JavaScript API. You also need a browser and its compatible WebDriver arrangement for the browser you intend to automate.
Install the binding in your project with npm install selenium-webdriver. The code below uses CommonJS. If your project uses ES modules, import the same APIs with import statements and ensure your project is configured for ESM; the filesystem APIs are available from node:fs/promises in either style.
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 glitchesCapture and save a PNG screenshot
driver.takeScreenshot() resolves to a Base64-encoded PNG string. Decode it when writing: passing 'base64' as the write encoding stores image bytes, whereas treating the string as ordinary text creates a file that is not a usable PNG. Selenium’s API describes capture as best effort, preferring the entire page, then the current window, the visible part of the current frame, and finally the display containing the browser. The exact scope depends on browser, driver, and environment; do not assume the generic method always produces a full-page image. See the JavaScript API and Selenium’s window and tab examples.
#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
Runnable CommonJS example
This small script navigates, saves a screenshot, and quits the driver even if navigation or capture fails. It assumes Chrome is configured for Selenium in your environment.
const { Builder, Browser } = require('selenium-webdriver');
const { writeFile, mkdir } = require('node:fs/promises');
const path = require('node:path');
async function saveScreenshot(driver, filePath) {
const base64Png = await driver.takeScreenshot();
await mkdir(path.dirname(filePath), { recursive: true });
await writeFile(filePath, base64Png, 'base64');
}
(async () => {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
try {
await driver.get('https://example.com');
await saveScreenshot(driver, path.join('artifacts', 'example.png'));
} finally {
await driver.quit();
}
})();
The Node filesystem API supports promise-based writes and directory creation. Await each write so errors are observable and later steps do not race the file operation. See Node.js v22 file-system documentation.
Wait for the state you want to capture
Capture after the page has reached the state that matters: navigation completion alone may not mean an asynchronously rendered component or image is ready. Prefer an explicit condition, such as waiting for a known element, using Selenium’s wait support, rather than adding an arbitrary sleep. Selenium’s API documents the driver and wait methods at the JavaScript API reference. Take the screenshot before calling driver.quit().
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Capture one element instead of the page
For focused evidence—such as a chart or a failing component—Selenium documents element screenshots. For example, after locating the element, call await element.takeScreenshot(true) to obtain its Base64 screenshot data and write it with the same 'base64' encoding. Element capture is useful when the surrounding page is irrelevant, but the resulting image is limited to that element rather than the whole page. Selenium’s examples show this pattern in its window and tab documentation.
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
Save screenshots from a test failure
Selenium does not automatically take a screenshot when an assertion fails. Your test framework or runner must provide a hook that can access both the failing test and the active driver. In that hook, create the artifact directory, capture the image, and give it a unique path derived from a sanitized test identifier plus a timestamp or worker identifier. Adapt the hook to your runner; there is no single universal hook API.
A helper can centralize the actual capture and file write:
const { writeFile, mkdir } = require('node:fs/promises');
const path = require('node:path');
async function captureToFile(driver, filePath) {
const base64Png = await driver.takeScreenshot();
await mkdir(path.dirname(filePath), { recursive: true });
await writeFile(filePath, base64Png, 'base64');
return filePath;
}
Call the helper in the failure path while the browser session still exists. If capture or writing also fails, report that artifact error separately and preserve the original test exception. Otherwise a secondary screenshot problem can obscure the failure you were trying to diagnose. This behavior is your hook’s responsibility, not an automatic Selenium feature.
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 & 11Crashes, 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 minuteUse collision-resistant filenames
Test titles can contain slashes, punctuation, or characters that are awkward in filenames. Sanitize the title and include a time or worker component; do not let parallel tests overwrite one shared failure.png. For example:
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.
function safeName(value) {
return value.replace(/[^a-z0-9_-]+/gi, '-').replace(/^-+|-+$/g, '').slice(0, 100) || 'test';
}
const fileName = `${safeName(testTitle)}-${Date.now()}-${workerId}.png`;
const screenshotPath = path.join('artifacts', fileName);
await captureToFile(driver, screenshotPath);
Choose an identifier source appropriate to your runner. A timestamp helps distinguish retries; a worker or process identifier helps separate concurrent workers. Avoid storing sensitive page content in artifacts unless your project’s access and retention controls permit it.
Persist test results separately from screenshots
A screenshot is an image artifact, not a test result. Let the selected test runner report pass/fail outcomes, titles, durations, and errors in the format its consumers need. Alternatively, write an intentional JSON summary from your hook or test harness. Mocha, for example, documents a JSON reporter; reporter availability and configuration should be checked for the Mocha version in your project: Mocha JSON reporter documentation.
Write a deliberate JSON summary
For a small custom summary, decide which fields downstream users need, then serialize those fields rather than trying to dump a driver or framework object. The following is an illustrative pattern, not a format Selenium guarantees:
const { writeFile, mkdir } = require('node:fs/promises');
const path = require('node:path');
async function saveResultSummary(resultPath, resultSummary) {
await mkdir(path.dirname(resultPath), { recursive: true });
await writeFile(resultPath, JSON.stringify(resultSummary, null, 2), 'utf8');
}
const resultSummary = {
runId,
testTitle,
status: 'failed',
error: error.message,
stack: error.stack,
screenshotPath,
timestamp: new Date().toISOString()
};
await saveResultSummary(path.join('artifacts', 'test-result.json'), resultSummary);
Populate values such as duration, browser capabilities, build identifier, or retry number only when your runner or harness actually supplies them. For a suite, a runner reporter is usually more suitable than having every parallel test overwrite a shared JSON file.
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
Choose a file layout that matches how results are consumed
- One file per test: Keeps screenshots and summaries easy to associate and avoids concurrent writes to one path, at the cost of more artifact files.
- Runner-generated report: Uses the runner’s supported format and metadata; configure it for the runner version and CI consumer.
- One aggregated JSON file: Convenient for downstream processing, but collect records safely and write the aggregate once, or use deliberate coordination. Do not issue overlapping writes to the same destination.
Node warns that repeated writeFile operations on the same file are unsafe unless a prior promise has settled. Use separate paths for parallel tests, await writes, or aggregate in memory and write once. The warning and API details are in the Node.js file-system documentation.
Make artifacts useful in local and CI runs
Create a known artifact directory before saving files, as the examples do with recursive mkdir. Keep screenshots and summaries under a path your test process can write to, and make the location available to your reporter or CI job. Local runs can inspect these files directly; a CI job generally needs a separate platform-specific artifact upload step for the directory.
Artifact upload and retention are CI configuration, not Selenium behavior. Configure your CI provider to upload the directory even when tests fail if you need failure evidence, and set retention according to that provider’s controls and your project’s data policy. There is no universal CI directory convention or retention period established by Selenium or Node.
Common problems and fixes
- The .png file contains unreadable text or cannot be opened: The Base64 string was probably written without decoding. Pass
'base64'towriteFile, as in the examples. - The screenshot path does not exist: Create its parent directory first with
mkdir(path.dirname(filePath), { recursive: true }); verify the process has permission to write there. - The screenshot is blank or shows an earlier state: Wait for the specific page condition or element that should be visible before capture. An arbitrary delay can be unreliable; use Selenium’s explicit wait facilities.
- The result is not a full-page image: The generic screenshot method makes a best effort across possible scopes and does not universally promise full-page capture. Verify the behavior with the target browser and driver if full-page output is required.
- A screenshot failure hides the assertion failure: Catch and report artifact errors separately while retaining the original exception and stack.
- Parallel tests overwrite one another’s artifacts: Include sanitized test identity and a timestamp or worker identifier in paths; avoid shared filenames.
- JSON is missing tests or is malformed: Do not let concurrent tests replace or append to a shared file without coordination. Use the runner’s reporter or collect results and write one completed summary.
- No artifact appears in CI: A local file write does not upload a file. Check the CI job’s artifact collection path, failure behavior, and retention settings for that specific platform.
- The browser remains open after a failure: Put
await driver.quit()in afinallyblock so cleanup runs on both success and error paths.
Or skip the browser setup
If your goal is a website screenshot rather than browser-driven test automation, ScreenshotNeo offers a screenshot API and MCP server. For a one-request capture, substitute the target URL and API key:
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.
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. Before capture, it can accept cookie/consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. This is an alternative for capturing websites, not a replacement for Selenium-driven interaction or your test runner’s result reporting.
Sign up for 1,000 free screenshots a month with no card.
Frequently Asked Questions
Can Selenium save a screenshot directly as a file?
The JavaScript binding returns Base64 PNG data; write that data to a file with Base64 decoding, as shown above.
Does Selenium save test results along with screenshots?
No. The selected test runner or your own harness owns result reporting; Selenium’s screenshot API captures browser imagery.
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.

