Recommended Free Tools
In Node.js, capture a Selenium screenshot with await driver.takeScreenshot(), then write the returned Base64 string to a file using the base64 encoding. Selenium captures images; your test runner—not WebDriver—owns test results. Use the runner’s reporter or save a deliberate JSON summary, and give each test a unique artifact path.
What you need before you start
The examples below use the Selenium JavaScript binding, the selenium-webdriver package, and Node.js. The current Selenium JavaScript API documentation specifies Node.js 22 or later; check the API documentation for supported Node release lines and package requirements before choosing an older runtime: Selenium WebDriver JavaScript API.
You also need a browser and its WebDriver support configured for your environment. The screenshot and file-writing code does not install or configure a browser. If your project is already using Selenium, keep its existing browser setup and add the capture functions where the driver is available.
Capture and save a screenshot
driver.takeScreenshot() resolves to a Base64-encoded PNG string. Decode it when writing the file by passing 'base64' as the write encoding; otherwise the Base64 characters are saved as text instead of PNG bytes. This CommonJS example creates the output folder if needed and waits for the file write to finish:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
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 example uses Chrome as the requested browser; use the browser you have configured. Selenium documents both the screenshot method and Base64 file output in its window and tab examples. For an ESM project, use import statements from selenium-webdriver, node:fs/promises, and node:path instead of require; the capture and write calls remain the same.
Use synchronous writing only when it fits
For a small, one-off script, Selenium’s documented example uses fs.writeFileSync('./image.png', encodedString, 'base64'). In async tests, promise-based writeFile lets the test await completion and report failures in its normal control flow. Node’s file-system documentation describes both interfaces and warns against overlapping writes to the same file: Node.js v22 file system documentation.
Choose the screenshot scope you actually need
Current page or browser view
driver.takeScreenshot() is the general WebDriver method. Its documented implementation makes a best effort to return, in order, an image of the entire page, the current window, the visible part of the current frame, or the whole display containing the browser. The actual result depends on browser, driver, and environment support. Do not assume this generic method guarantees a full-page image in every setup. If full-page coverage is essential, verify the result in the target browser and use a browser-specific approach if needed.
A single element
For focused evidence—such as a broken banner or a component with an unexpected state—locate the element and call await element.takeScreenshot(true). Selenium’s example uses this element screenshot method: Selenium window and tab examples.
const element = await driver.findElement({ css: '[data-testid="checkout-summary"]' });
const base64Png = await element.takeScreenshot(true);
await mkdir('artifacts', { recursive: true });
await writeFile('artifacts/checkout-summary.png', base64Png, 'base64');
As with page captures, wait until the element exists and reflects the state you intend to inspect before taking its screenshot.
Capture after the page is ready
Take the screenshot after navigation and after the relevant page state is available. An arbitrary delay can make tests slow without guaranteeing readiness. Prefer a condition that describes what the test needs, using WebDriver’s wait support documented in the JavaScript API.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
await driver.get('https://example.com');
await driver.wait(async () => {
const title = await driver.getTitle();
return title.includes('Example');
}, 10000, 'Expected page title did not appear');
await saveScreenshot(driver, 'artifacts/example-ready.png');
Choose a condition appropriate to the page: a known title, a visible element, or another observable state your test needs. A successful navigation alone does not establish that asynchronously rendered content, fonts, or images have finished loading.
Save useful failure evidence without hiding the test failure
A runner hook is the right place to connect screenshots to failing tests because it can access both the test outcome and the WebDriver instance. Exact hook names and access to test metadata differ by framework, so integrate this pattern into the runner you actually use rather than treating it as a Selenium feature.
- When a test fails, derive a filename from a sanitized full test title, plus a timestamp or worker identifier to avoid collisions.
- Attempt the screenshot and await the image write before the driver is quit.
- If capture or file writing fails, report that artifact error separately and preserve the original test exception as the primary failure.
- Let the test runner report the final outcome. If you need custom metadata, save a separate JSON summary or use a runner reporter.
Illustrative helper for a failing-test hook:
const { writeFile, mkdir } = require('node:fs/promises');
const path = require('node:path');
function safeFilePart(value) {
return value
.replace(/[^a-z0-9_-]+/gi, '-')
.replace(/^-+|-+$/g, '')
.slice(0, 100) || 'test';
}
async function captureFailureArtifact(driver, testTitle, runId) {
const fileName = `${safeFilePart(testTitle)}-${safeFilePart(runId)}.png`;
const filePath = path.join('artifacts', 'screenshots', fileName);
const base64Png = await driver.takeScreenshot();
await mkdir(path.dirname(filePath), { recursive: true });
await writeFile(filePath, base64Png, 'base64');
return filePath;
}
// In your runner's failure hook, while driver is still open:
try {
const screenshotPath = await captureFailureArtifact(driver, test.fullTitle(), runId);
console.error(`Failure screenshot: ${screenshotPath}`);
} catch (artifactError) {
console.error('Could not save failure screenshot:', artifactError);
// Keep the runner's original test error as the test failure.
}
This is an integration pattern, not a universal runner hook: adapt identifiers such as test.fullTitle() and runId to your framework. Keep the screenshot attempt before driver.quit(), usually in a finally cleanup path that still guarantees the driver is closed.
Persist test results separately from screenshots
Selenium’s screenshot API returns an image; it does not provide a test-results API. Test status, titles, durations, errors, and reporter output belong to your chosen test runner. For example, Mocha documents a JSON reporter, though its cited reporter documentation is in the legacy documentation: Mocha JSON reporter documentation. Confirm the reporter options against the installed Mocha version.
If downstream tooling needs a small custom record, construct it from values your runner actually provides, then write it as JSON. The following is illustrative; the fields are application choices, not values supplied automatically by Selenium:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const resultSummary = {
runId,
testTitle: test.fullTitle(),
status: 'failed',
error: {
message: error.message,
stack: error.stack
},
screenshotPath
};
await writeFile(
resultPath,
JSON.stringify(resultSummary, null, 2),
'utf8'
);
Useful optional fields may include a build or run identifier, browser or capabilities, timestamp, and duration if your runner supplies it. Avoid serializing entire framework objects: they may contain circular references, unstable internals, or sensitive data. Decide what consumers need and write a stable schema.
Per-test files or one summary file?
- Per-test artifacts: separate screenshot and result files reduce accidental name collisions and make a single failure easier to inspect.
- One run summary: a single JSON document is convenient for downstream processing. Accumulate test records in memory and write once after the run, or coordinate writes deliberately.
- Concurrent tests: do not have parallel workers overwrite one shared filename. Node warns repeated overlapping writes to a file without waiting for a prior write to settle are unsafe. Await writes and use unique paths, or have one process aggregate results.
Keep artifacts available in CI
Writing to artifacts/ only creates files in the job’s working environment; it does not guarantee those files will be retained after the job ends. Configure your CI platform to upload that directory as a job artifact and set retention using that platform’s artifact settings. Directory conventions, retention limits, and upload syntax are platform-specific, so follow the documentation for your CI provider and repository configuration.
For easier diagnosis, keep related files together—for example, a screenshot subdirectory and a result JSON directory—and include a run or worker identifier in names produced by parallel jobs. Make sure the capture and all file writes finish before the test process exits; an unawaited write can leave missing or incomplete evidence.
Common problems and fixes
The output file is not a readable PNG
Cause: the Base64 string was written as ordinary text. Fix: pass 'base64' as the encoding in writeFile(filePath, base64Png, 'base64').
The screenshot file is missing
Cause: its parent directory does not exist, the write was not awaited, or the process ended before it completed. Fix: create the directory with mkdir(directory, { recursive: true }), await the write, and check the resolved path relative to the process working directory.
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 reinstallCrashes, 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 minuteRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
The image captures the wrong state or appears incomplete
Cause: the capture ran before the expected content was ready, or the browser’s screenshot scope differs from what you assumed. Fix: wait for an observable expected condition, capture only after it is met, and verify whether the target browser returns the full page or only a window/frame view.
Parallel tests overwrite each other’s evidence
Cause: multiple tests target the same screenshot or JSON path. Fix: add a sanitized test identifier and run/worker identifier, and avoid unsynchronized writes to one shared result file.
A screenshot error replaces the useful test error
Cause: the capture hook throws while handling an already failed test. Fix: catch and report artifact failures separately; retain the original test exception and still close the driver.
Artifacts exist locally but not after CI finishes
Cause: the CI job did not upload them or its retention policy expired them. Fix: configure the platform’s artifact upload and retention settings for the directory your tests write.
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 →Or skip the browser setup
If the task is to capture a URL rather than test it through WebDriver, ScreenshotNeo provides a screenshot API: ScreenshotNeo. One GET request returns a screenshot or PDF; the cURL example saves a WebP image. See the ScreenshotNeo API documentation for request options.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
- Cookie banners and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
- Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
- An MCP server offers
take_screenshot,get_page_info, andcapture_pdftools for AI agents and MCP clients. - The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Frequently Asked Questions
What does `takeScreenshot()` return in Selenium for Node.js?
A promise that resolves to a Base64-encoded PNG string. Write it with Base64 decoding, such as `writeFile(path, data, ‘base64’)`.
Can I capture an element instead of the page?
Yes. Find the element and call `await element.takeScreenshot(true)`, then save the returned Base64 PNG as an image.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Does Selenium save test results along with screenshots?
No. Selenium provides the browser screenshot; the test runner provides result reporting. Use the runner’s reporter or write a separate JSON record.
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.

