Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Take a Web Page Screenshot with Selenium in Ruby

Use Selenium Ruby’s save_screenshot method to save a PNG of the current viewport, with notes on element and conditionally supported full-page captures.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Use Selenium Ruby’s save_screenshot method after opening the page. By default, it saves a PNG of the browser’s current viewport—not the entire page.

Take a viewport screenshot in Ruby

Install the selenium-webdriver gem and make sure a compatible browser and driver are available. This example opens a page, saves a screenshot, and quits the browser even if an error occurs:

As an Amazon Associate I earn from qualifying purchases.

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome

begin
  driver.get 'https://example.com/'
  driver.save_screenshot('./screenshot.png')
ensure
  driver.quit
end

The key call is driver.save_screenshot('./screenshot.png'). Navigate to the target page first; the screenshot is taken from the active browser context. Selenium’s WebDriver documentation demonstrates navigation and saving a screenshot, while the Ruby API reference describes the output as a PNG of the viewport.

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

Choose the capture area

Current viewport

The basic driver call captures what is visible in the current browser viewport. It does not imply a full-page image of content below the fold.

#1 Best Overall

Full page, when supported

The current Ruby API documents save_screenshot(png_path, full_page: false). You can request a full-page capture with driver.save_screenshot('./full-page.png', full_page: true), but only where the installed Selenium/browser combination supports it. Otherwise Selenium may raise an unsupported-operation error. Check the documentation for your installed gem and browser rather than assuming this option works everywhere.

One element

To capture a particular element, locate it and call its screenshot method:

element = driver.find_element(css: '#main-content')
element.save_screenshot('./main-content.png')

Use a .png extension for element screenshots too. The Ruby API describes the saved screenshot as PNG data and warns when the filename extension is not .png.

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

Output path and cleanup

  • Use a writable destination and create any parent directory before saving; the method opens the requested path for binary writing.
  • Keep the filename extension as .png so it matches the data Selenium writes.
  • Keep driver.quit in an ensure block so the browser session is closed if navigation or capture fails.

Common problems

  • Unsupported full-page capture: Remove full_page: true to take a viewport screenshot, or check whether the exact browser and Selenium version support full-page capture.
  • File cannot be written: Choose a writable path and make sure its parent directory exists.
  • Image extension warning: Change the screenshot filename to end in .png; the API writes PNG data.
  • Screenshot is only part of the page: The ordinary driver screenshot is viewport-only. Use full-page mode only if supported by your combination, or capture a specific element when that is the desired scope.

Or skip the browser setup

If you need a screenshot without managing a local Selenium browser, ScreenshotNeo offers a single-request API. See the ScreenshotNeo documentation for request options.

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

ScreenshotNeo accepts cookie banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Create a free ScreenshotNeo account to start with 1,000 screenshots a month and no card.

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

Frequently Asked Questions

Does Selenium Ruby save screenshots as PNG?

Yes. The Ruby screenshot API writes PNG data; use a filename ending in .png.

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

Does save_screenshot capture the whole web page?

By default, it captures the current viewport. Full-page capture depends on support in the installed Selenium and browser combination.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.