If you require full-page screenshots in Selenium, save yourself some time and use the following:
- Firefox 47.0.1
- Latest version of selenium-webdriver Ruby Gem (I am on 3.0.7)
This should be the only code you need:
caps = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false) driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps) driver.get 'https://www.nytimes.com' driver.save_screenshot 'screenshot.png' driver.quit
Version combinations matter a lot because the underlying automation driver has gone through a lot of changes, specifically for Firefox. Firefox has a new automation driver called Marionette, but it’s very new and not widely supported. In Selenium 3.x, Marionette defaults to off and uses the legacy driver.
Most browsers are now following the W3C standard, which means screenshots will be of the view port, not the entire full rendered page. This isn’t super helpful if you want to capture a long page and the footer content is needed.
You can read more on the Selenium issue about why this doesn’t work in some version combinations.
If you want to use Chrome, good luck. There has been an open bug report for Chrome for years about this without a fix. Given how a lot of people have moved on to taking screenshots, scrolling the page, then stitching images together, it doesn’t seem likely this will be natively possible anytime soon. The screenshot-scroll-stitch method isn’t very useful if you have header content that stays stuck to the top of the screen.
If you are using this kind of setup with Capybara on top, you’ll likely run into even more problems. Capybara doesn’t appear to fully support Marionette yet, so you may need to downgrade and lock versions to get everything working correctly.