Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
With SeleniumLibrary, put Capture Page Screenshot in your test or user keyword. It captures the current WebDriver page and embeds the image in Robot Framework’s log.html. The default form also writes a PNG file; use EMBED when you want an in-log image without a separate file, or register the keyword as SeleniumLibrary’s failure handler for automatic evidence after failed browser actions.
The direct SeleniumLibrary solution
Import SeleniumLibrary, open a browser, and call the page-screenshot keyword at the point where you need evidence:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Capture Current Page
Open Browser https://example.com chrome
Capture Page Screenshot
[Teardown] Close All Browsers
Capture Page Screenshot takes the current WebDriver page image and embeds it in Robot Framework’s generated log. With the normal default, SeleniumLibrary also saves an image file. After the run, open log.html and select the screenshot entry to view it.
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 →Choose whether to save a file
File plus an embedded log image
Call the keyword without an argument when you want both a standalone artifact and the convenient image in log.html:
#1 Best Overall
Capture Page Screenshot
The default filename is selenium-screenshot-{index}.png. SeleniumLibrary replaces {index} with a running unique number, so repeated captures do not overwrite one another. You can supply your own filename while retaining the file-and-log behavior:
Capture Page Screenshot checkout-error-{index}.png
Keep {index} in a repeated-capture name. A fixed name is useful only when you deliberately want the latest capture to replace an earlier one.
Embed only
Pass the literal filename EMBED to store the image as Base64 in log.html without creating a screenshot file:
Recommended Free Tools
Capture Page Screenshot EMBED
This is useful for small, self-contained reports that should not leave a directory full of image artifacts. The image remains available when the log is copied as a single HTML report, provided the report itself is kept intact.
Return Base64 for custom HTML
SeleniumLibrary also documents BASE64 output. Capture the encoded data into a variable, then place it in your own HTML message or template:
*** Test Cases ***
Put Screenshot In Custom HTML
${image}= Capture Page Screenshot BASE64
Log <img src="data:image/png;base64,${image}" alt="WebDriver screenshot"> html=True
Use this form when the screenshot must be combined with your own diagnostic text or markup. EMBED is the simpler choice when the standard SeleniumLibrary log entry is sufficient.
Control where screenshot files are written
When you save a file, configure an output directory explicitly so CI artifacts are predictable:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Capture Into Artifact Folder
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots
Open Browser https://example.com chrome
Capture Page Screenshot home-{index}.png
[Teardown] Close All Browsers
Set Screenshot Directory creates the directory when necessary. If you never configure one, SeleniumLibrary uses the directory in which Robot Framework writes the log. In a normal run that means the screenshot file sits beside log.html and is linked or embedded from that report.
SeleniumLibrary also documents EMBED as a screenshot-root setting. If you configure that mode for your suite, normal page or element screenshot calls can be embedded directly instead of being written as ordinary files. Make the choice deliberately: file output is easier to archive independently, while embedded output makes a portable HTML report.
Capture automatically when a SeleniumLibrary keyword fails
To get a screenshot after browser-operation failures, register Capture Page Screenshot as the SeleniumLibrary failure keyword. The handler runs after a SeleniumLibrary keyword fails:
*** Settings ***
Library SeleniumLibrary run_on_failure=Capture Page Screenshot
*** Test Cases ***
Evidence On Failure
Open Browser https://example.com chrome
Click Element css:#button-that-may-not-exist
[Teardown] Close All Browsers
The same setting can be changed at runtime:
*** Test Cases ***
Set Failure Handler During Test
Register Keyword To Run On Failure Capture Page Screenshot
Open Browser https://example.com chrome
Click Element css:#submit
A custom failure handler must take no arguments. If a failure occurs before a browser is opened, or after the browser has already been closed, there may be no active page to capture; the original test error is still the useful failure in that situation.
Outdated 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 matchWindows 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 reinstallA practical suite pattern
For a maintainable suite, set the directory once, enable the failure hook, and take deliberate checkpoints only where they add context:
*** Settings ***
Library SeleniumLibrary run_on_failure=Capture Page Screenshot
Suite Setup Open Test Browser
Suite Teardown Close All Browsers
*** Keywords ***
Open Test Browser
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots
Open Browser https://example.com chrome
Set Window Size 1440 1000
*** Test Cases ***
Checkout Checkpoints
Capture Page Screenshot 01-start-{index}.png
Click Element css:#start
Capture Page Screenshot 02-after-start-{index}.png
Input Text css:#email [email protected]
Click Element css:#continue
Capture Page Screenshot 03-checkout-{index}.png
Use explicit checkpoints for state transitions that are hard to infer from a failure alone. The failure hook then covers unexpected errors without requiring every test to repeat the same capture keyword.
What exactly is being captured?
| Keyword or library | Capture target | Typical output | Trigger |
|---|---|---|---|
Capture Page Screenshot (SeleniumLibrary) |
The current Selenium WebDriver page | Embedded in log.html, optionally with a file; can return Base64 |
Explicit call or SeleniumLibrary failure hook |
Take Screenshot (Robot Framework Browser) |
A page controlled by Browser | Browser-library screenshot output, with documented EMBED support |
Explicit Browser keyword |
Take Screenshot (Robot Framework Screenshot library) |
The desktop, not just the WebDriver page | Desktop image embedded or linked in the report | Explicit Screenshot-library keyword |
These are different libraries and capture targets. If your test imports SeleniumLibrary and controls a Selenium WebDriver session, use Capture Page Screenshot. A desktop screenshot can include windows or browser chrome outside the page, while a WebDriver capture represents the page viewport and its rendered content.
Common problems and fixes
No image appears in the log
- Confirm the SeleniumLibrary import and spelling:
Capture Page Screenshot. - Open the generated
log.html, not onlyreport.html; detailed keyword-level output is in the log. - Check that the test reached the capture call and that the browser session was still open.
- If you used a file path, retain the screenshot directory and its files when moving the HTML report. Use
EMBEDfor a self-contained image.
The file is missing, but the test passed
You may have used Capture Page Screenshot EMBED, which intentionally creates no standalone file. You may also be looking in the wrong directory: without Set Screenshot Directory, SeleniumLibrary writes beside the Robot Framework log.
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 glitchesEvery capture overwrites the previous one
Use the indexed default or include {index} in your custom filename, for example state-{index}.png. A fixed filename is not unique across repeated calls.
The failure hook causes another error
A failure handler cannot accept arguments. Register the keyword by name only, and make sure the browser still exists when the original SeleniumLibrary keyword fails. If your teardown closes the browser first, do not expect a later capture to work.
The report works locally but not in CI
- Publish the entire Robot output directory, including
log.htmland any screenshot directory. - Prefer
${OUTPUT DIR}plus${/}rather than a developer-specific absolute path. - For a single transferable HTML artifact, use
EMBEDor customBASE64HTML. - Ensure the CI browser has actually rendered the page before capturing; wait for the relevant element or application state in the test.
The image is blank or shows an intermediate state
A screenshot records exactly what WebDriver has rendered at that instant. Add an explicit wait for the page element or state that proves the transition completed, then capture. A screenshot keyword does not replace synchronization.
Performance, storage and reliability choices
- Capture only useful points. Every file increases CI artifact size, and embedding large images increases
log.htmlsize. - Use failure capture for broad coverage. It records unexpected states without adding a screenshot call to every step.
- Use named checkpoints for diagnosis. Numbered files make it easy to correlate a visual state with a business step.
- Choose portability consciously. Embedded images travel with the HTML log; files are easier to inspect, process, or retain under separate artifact policies.
- Keep the browser alive through capture. Put browser shutdown in teardown after the final evidence opportunity.
Or skip the browser setup
If your goal is a URL image rather than evidence from an already-running Robot test, ScreenshotNeo provides a single screenshot API request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can 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 whether it was billed. Its MCP server provides take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.
See the ScreenshotNeo documentation for parameters and authentication. A direct call 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)
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}`);
Plans include 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000 shots. Sign up at ScreenshotNeo’s free account page.
FAQ
Can I attach a screenshot to a passed test as well as a failed test?
Yes. Place Capture Page Screenshot at the desired checkpoint; the failure registration is independent and only handles SeleniumLibrary keyword failures.
Does EMBED mean the screenshot is stored in a PNG file?
No. With EMBED, SeleniumLibrary puts Base64 image data in log.html and does not create a separate screenshot file.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Which keyword should I use with Robot Framework Browser?
Browser is a separate library with its own Take Screenshot keyword. Do not substitute it for SeleniumLibrary’s WebDriver keyword unless the test was built with Browser.
Can a failure handler receive the failed keyword name as an argument?
Not through SeleniumLibrary’s registered failure-keyword mechanism. The configured handler must take no arguments.
Frequently Asked Questions
Can I attach a screenshot to a passed test as well as a failed test?
Yes. Place Capture Page Screenshot at the desired checkpoint; the failure registration is independent and only handles SeleniumLibrary keyword failures.
Does EMBED mean the screenshot is stored in a PNG file?
No. With EMBED, SeleniumLibrary puts Base64 image data in log.html and does not create a separate screenshot file.
Free tools Windows power users keep installed
One-click scans. No signup required.
Which keyword should I use with Robot Framework Browser?
Browser is a separate library with its own Take Screenshot keyword. Do not substitute it for SeleniumLibrary’s WebDriver keyword unless the test was built with Browser.
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.

