Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium’s Ruby save_screenshot method after the browser reaches the state you want to record. It writes the current viewport as a PNG; use full_page: true only when the active driver supports full-page capture, or use screenshot_as when your application needs PNG bytes or Base64 in memory.

Save a Selenium screenshot in Ruby

Install the Ruby binding, start a WebDriver, navigate, wait for the page state you need, and save the viewport:

gem install selenium-webdriver
require "selenium-webdriver"

driver = Selenium::WebDriver.for :chrome
begin
  driver.navigate.to "https://example.test"
  driver.save_screenshot("tmp/example.png")
ensure
  driver.quit
end

save_screenshot("tmp/example.png") records the browser’s current viewport and writes PNG data to that path. Create tmp first if it does not exist, and make sure the process can write there. Use a filename ending in .png; Selenium warns when the extension does not match PNG.

Capture the right browser state

A screenshot is a point-in-time recording. Selenium does not wait for a visual state automatically when save_screenshot runs. Navigate, perform clicks or form actions, and wait for the content that must appear before taking the shot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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

Wait for an element before capture

require "selenium-webdriver"

driver = Selenium::WebDriver.for :chrome
wait = Selenium::WebDriver::Wait.new(timeout: 15)

begin
  driver.navigate.to "https://example.test/dashboard"
  wait.until { driver.find_element(css: "[data-testid='dashboard-ready']").displayed? }
  driver.save_screenshot("tmp/dashboard.png")
ensure
  driver.quit
end

Choose a selector that represents the finished state rather than waiting for an arbitrary sleep. If the page contains animations, lazy images, or data loaded after the initial document, wait for the relevant element and, when necessary, for its text or attributes to reach the expected value.

Interact before taking the shot

driver.find_element(css: "button[data-action='open-menu']").click
wait.until { driver.find_element(css: "nav[aria-expanded='true']").displayed? }
driver.save_screenshot("tmp/open-menu.png")

Put all interactions and waits before the screenshot call. The image reflects the active window, scroll position, viewport size, cookies, and other browser state at that moment.

Take a full-page screenshot

Pass full_page: true when you need the document beyond the visible viewport:

driver.save_screenshot("tmp/full-page.png", full_page: true)

Full-page capture is driver-dependent, not a universal Selenium capability. The Ruby implementation checks whether the driver responds to save_full_page_screenshot and raises Selenium::WebDriver::Error::UnsupportedOperationError when it does not. Check support before requesting it and provide a viewport fallback:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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
path = "tmp/page.png"

if driver.respond_to?(:save_full_page_screenshot)
  driver.save_screenshot(path, full_page: true)
else
  warn "Full-page screenshots are not supported by this driver; saving the viewport"
  driver.save_screenshot(path)
end

A capability check reduces surprises when the same test runs with a different browser, driver, remote session, or grid node. Even with support, very tall pages can create large images and may take longer than a viewport shot.

Return PNG bytes or Base64 without writing a file

Use screenshot_as when you need to upload the image, attach it to a test report, or embed it elsewhere:

png_bytes   = driver.screenshot_as(:png)
base64_data = driver.screenshot_as(:base64)

Write returned PNG bytes yourself

png_bytes = driver.screenshot_as(:png)
File.binwrite("tmp/from-bytes.png", png_bytes)

Embed the Base64 result in HTML

base64_data = driver.screenshot_as(:base64)
html = "<img alt="Selenium capture" src="data:image/png;base64,#{base64_data}">"
File.write("tmp/report.html", html)

The documented formats are :png and :base64. Passing another format raises UnsupportedOperationError. :png gives binary image data; :base64 gives text suitable for a data URL or a JSON payload.

Capture one element

Selenium’s TakesScreenshot interface is available on driver and element objects when the binding and browser driver support element capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • 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.
card = driver.find_element(css: "article[data-testid='pricing-card']")
card.save_screenshot("tmp/pricing-card.png")

Element capture is useful for a component-level regression artifact, but support should be verified in the browser and driver combination used by your test suite. If it is unavailable, crop a full viewport image in your own image pipeline or capture with a service that supports CSS-selector targeting.

Choose the output and scope

Need Ruby call Result Portability
Save a normal screenshot save_screenshot("path.png") PNG file of the current viewport Standard driver screenshot behavior
Save the entire page save_screenshot("path.png", full_page: true) Full-page PNG when supported Conditional; may raise UnsupportedOperationError
Get binary data screenshot_as(:png) PNG bytes in memory Use for uploads or custom storage
Get text data screenshot_as(:base64) Base64-encoded screenshot Use in HTML data URLs or API payloads
Capture a component element.save_screenshot("element.png") Element image when supported Verify target driver support

Use a reliable Ruby capture wrapper

Put driver cleanup in ensure so a failed navigation, timeout, or screenshot does not leave a browser process running. Return the path or bytes your test runner needs:

require "selenium-webdriver"

def capture_page(url, output_path)
  driver = Selenium::WebDriver.for :chrome
  wait = Selenium::WebDriver::Wait.new(timeout: 20)

  begin
    driver.navigate.to url
    wait.until { driver.find_element(css: "body").displayed? }
    driver.save_screenshot(output_path)
    output_path
  ensure
    driver.quit
  end
end

capture_page("https://example.test", "tmp/example.png")

For test diagnostics, capture in an exception handler before quitting if the failure occurs after the browser has reached a useful state. Keep artifact names unique in parallel runs, for example by including the test name and timestamp, and avoid sharing one driver instance between concurrent examples.

Troubleshoot common failures

Symptom Likely cause Fix
Errno::ENOENT or no image appears The destination directory does not exist or is not writable. Create the directory, use an absolute or known-good path, and verify write permissions. Keep the .png extension.
UnsupportedOperationError with full_page: true The active browser driver does not implement full-page screenshots. Check driver.respond_to?(:save_full_page_screenshot), save the viewport instead, or run on a driver that supports the capability.
Screenshot shows a loading shell Capture happened before asynchronous content finished. Wait for a meaningful selector, text, or state attribute rather than relying on a fixed sleep.
Wrong tab or window is captured The driver is focused on a different window handle. Switch to the intended window before waiting and capturing.
Only part of a long page is visible The call captured the viewport, or full-page capture is unsupported. Request full_page: true only after a capability check, or use viewport captures while scrolling and stitch them in a separate workflow.
Element screenshot fails The element is not displayed, detached, outside the supported state, or element capture is unavailable. Wait for the element, locate it again after DOM updates, scroll it into view if needed, and verify driver support.
Intermittent blank or stale image A transition, lazy image, or navigation is still in progress. Wait for the final URL or a stable selector, disable test animations where appropriate, and capture only after the page reaches a deterministic state.

Performance, reliability, and storage considerations

  • Capture late, not repeatedly: screenshots involve browser and image encoding work. Take only the artifacts needed for assertions or diagnostics.
  • Control dimensions: set a consistent window size when comparing images. A different viewport changes responsive layout and therefore the pixels.
  • Prefer bytes for pipelines: screenshot_as(:png) avoids a temporary file when an uploader or test reporter accepts binary data. Base64 is convenient in JSON or HTML but increases payload size compared with raw bytes.
  • Protect sensitive data: screenshots can contain account details, tokens displayed in a page, or personal information. Restrict artifact access and remove files according to your test-retention policy.
  • Use cleanup on every path: an ensure block prevents orphaned browser processes and makes repeated captures more predictable.
  • Expect full-page trade-offs: a tall page produces a larger image and can expose driver-specific limitations. Use viewport shots when a full document is not required.

Or skip the browser setup

If you need a URL screenshot rather than a browser-driven test, ScreenshotNeo provides a single HTTP request and an MCP server for AI agents. 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 each response identifies the result with X-Page-Verdict and X-Billed headers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

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)

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}`);

See the ScreenshotNeo documentation for authentication and options. The service supports PNG, JPEG, WebP, and PDF output; full-page capture with lazy images loaded; CSS-selector element capture; dark mode; device presets and custom viewports; retina scale; PDF paper size, margins, landscape, and page ranges; custom CSS and JavaScript; clicks; selector, delay, or network-idle waits; ad, tracker, request, and resource blocking; custom headers, cookies, user agents, and Authorization; timezone and geolocation; transparent backgrounds; resizing; selectable cache TTLs; signed image links; asynchronous jobs with signed webhooks; bulk capture of up to 100 URLs per call; a usage API; an OpenAPI specification; and familiar parameter names for easier migration.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

Plans

Plan Allowance Price
Free 1,000 shots/month $0, no card
Starter 3,000 shots $5
Growth 15,000 shots $15
Pro 60,000 shots $39
Scale 250,000 shots $99
Business 1,000,000 shots $249

Yearly billing gives two months free, and every feature is available on every plan. The MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. Start with 1,000 free screenshots a month without a card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently asked questions

Can Selenium capture a screenshot before a page finishes loading?

Yes, but it records whatever is currently rendered. If the intended artifact requires late-loading content, wait for a page-specific completion signal before calling the screenshot method.

Is a full-page image identical across Chrome and other drivers?

No. Full-page support and rendering details are driver-dependent. Keep the browser, driver, viewport, and page state consistent when pixel-level comparisons matter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should a production service keep one WebDriver open for every request?

That depends on isolation, concurrency, and startup cost. Reusing a controlled session can reduce startup overhead, while short-lived sessions simplify cleanup and prevent state leakage. Whichever model you choose, isolate cookies and user data and always close the driver on errors.

Best Value
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【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.

Frequently Asked Questions

Can Selenium capture a screenshot before a page finishes loading?

Yes, but it records whatever is currently rendered. Wait for a page-specific completion signal when the image must include late-loading content.

Is a full-page image identical across Chrome and other drivers?

No. Full-page support and rendering details are driver-dependent, so keep browser, driver, viewport, and page state consistent for pixel comparisons.

Should a production service keep one WebDriver open for every request?

Choose based on isolation, concurrency, and startup cost. Reused sessions can reduce startup overhead; short-lived sessions simplify cleanup and limit state leakage. Always close the driver on errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.