The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use Selenium’s Ruby WebDriver with Chrome’s --headless=new option, open the page, and call save_screenshot. The method saves the current viewport as a PNG. Put driver.quit in an ensure block so Chrome closes even if navigation or capture fails.
Capture a viewport screenshot with Ruby and headless Chrome
Install the Selenium gem, then save this as a Ruby script. Selenium Manager can manage the browser driver automatically in supported recent setups, so a separate driver-management gem is not the default requirement. See Selenium’s WebDriver getting-started guidance.
As an Amazon Associate I earn from qualifying purchases.
require 'selenium-webdriver'
options = Selenium::WebDriver::Options.chrome
options.add_argument('--headless=new')
driver = Selenium::WebDriver.for :chrome, options: options
begin
driver.get('https://example.com')
driver.save_screenshot('screenshot.png')
ensure
driver.quit
end
Run it in the Ruby environment where selenium-webdriver is installed. The parent directory for screenshot.png must already exist and be writable. Selenium’s Ruby API describes save_screenshot as saving a PNG to the given path: Ruby Driver API.
Recommended Free Tools
Wait for the page state you need
driver.get navigates to the URL, but a page can continue rendering or load content asynchronously. If the screenshot must include a particular element, wait for that element instead of relying on an arbitrary sleep. For example:
#1 Best Overall
- SLIM. LIGHTWEIGHT. READY TO GO: The all-new slim design is perfect for busy lives on the go.
- SKILLFULLY DESIGNED. MILITARY TOUGH: Built with premium craftsmanship to withstand the occasional drop or ding.
- ALL-DAY, ALL-IN-ONE CHARGING: Power through your school day – and beyond – with a long-lasting 12-hour battery.¹
- 3X FASTER THAN THE PREVIOUS GENERATION OF WIFI: Crush your schoolwork in record time with Wi-Fi that’s three times faster than the previous generation of Wi-Fi.
- YOUR PHONE AND CHROMEBOOK WORK BETTER TOGETHER: Easily transfer files between devices, and control your phone right from your Chromebook.
wait = Selenium::WebDriver::Wait.new(timeout: 10)
wait.until { driver.find_element(css: '#main-content').displayed? }
driver.save_screenshot('screenshot.png')
Place the wait and capture inside the same begin block as navigation, before the ensure that quits the driver. Replace #main-content with a selector present on the page; a missing selector or a timeout means the capture will not proceed.
Set a consistent viewport for repeatable images
The default capture is the current viewport, not automatically the entire document. Set a window size to make visual-test screenshots more consistent:
driver.manage.window.size = Selenium::WebDriver::Dimension.new(1440, 900)
driver.get('https://example.com')
driver.save_screenshot('screenshot.png')
Choose dimensions appropriate to your test and keep them fixed between runs. Differences in device scale, fonts, browser version and page timing can still change rendered pixels. Selenium documents window sizing in its WebDriver windows documentation.
Rank #2
- FOR HOME, WORK, & SCHOOL – With an Intel processor, 14-inch display, custom-tuned stereo speakers, and long battery life, this Chromebook laptop lets you knock out any assignment or binge-watch your favorite shows..Voltage:5.0 volts
- HD DISPLAY, PORTABLE DESIGN – See every bit of detail on this micro-edge, anti-glare, 14-inch HD (1366 x 768) display (1); easily take this thin and lightweight laptop PC from room to room, on trips, or in a backpack.
- ALL-DAY PERFORMANCE – Reliably tackle all your assignments at once with the quad-core, Intel Celeron N4120—the perfect processor for performance, power consumption, and value (2).
- 4K READY – Smoothly stream 4K content and play your favorite next-gen games with Intel UHD Graphics 600 (3) (4).
- MEMORY AND STORAGE – Enjoy a boost to your system’s performance with 4 GB of RAM while saving more of your favorite memories with 64 GB of reliable flash-based eMMC storage (5).
Viewport versus full-page capture
save_screenshot captures the current browsing context’s viewport. The Ruby API documents a full_page: option only for drivers that support it; other drivers may raise an unsupported-operation error. Check the API and your driver before depending on full-page output: Selenium Ruby screenshot API.
Manage Chrome and ChromeDriver
Recent Selenium releases include Selenium Manager, which can locate or manage a compatible driver in supported environments. For offline or controlled builds, provide browser and driver binaries explicitly. Chrome’s Selenium documentation says Chrome and ChromeDriver should have matching major versions: Selenium Chrome documentation.
The older options.headless = true pattern is removed in current Selenium Ruby guidance; use options.add_argument('--headless=new') instead. Selenium’s setup and browser guidance covers current options and driver management: Selenium WebDriver documentation.
Rank #3
- Storage: 16GB Flash Memory
- OS: Chrome OS
- Screen Size: 11.6"
Troubleshoot common failures
- Ruby cannot load selenium-webdriver: Install the gem in the same Ruby environment used to run the script, then retry.
- Chrome or ChromeDriver cannot start: Confirm Chrome or Chromium is installed and accessible. Check the actual exception and whether Selenium Manager can locate or download a compatible driver. In restricted or offline environments, configure compatible binaries yourself.
- Driver version error: Check that Chrome and ChromeDriver have matching major versions, as required by Selenium’s Chrome guidance.
- Permission denied or missing screenshot: Verify the output directory exists and the running process can write to it. Use an explicit path if the script’s working directory is not what you expect.
- Blank or incomplete image: Wait for a page element that signals the required content is ready. A page load completing does not necessarily mean every asynchronous element has rendered.
- Browser processes remain after an error: Keep
driver.quitin anensureblock, not only at the end of the successful path.
Use Chrome’s command line for a one-off capture
If you do not need Ruby-driven navigation, assertions or test integration, Chrome’s headless command-line screenshot option may be simpler. Chrome for Developers documents --headless --screenshot and --window-size: Chrome Headless documentation. Selenium is the more natural fit when the screenshot is one step in a Ruby automation flow.
Or skip the browser setup
For a hosted capture, ScreenshotNeo takes a URL in one GET request and returns an image or PDF. Cookie banners, popups and chat widgets are removed before the shot; bot checks, blank pages and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000.
cURL example, saving a WebP screenshot of the sample URL:
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 options and response details. You can also use the API with Python or Node.js:
Rank #4
- Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Sign up for ScreenshotNeo to get 1,000 free screenshots a month with no card.
Frequently Asked Questions
What file format does Selenium Ruby save?
save_screenshot saves PNG output; use a .png filename.
Does Selenium’s screenshot method capture the whole page?
By default it captures the viewport. Full-page capture depends on driver support.
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.




