Is it possible to take a screenshot of the whole page with Selenium/Capybara?

TrashyMcTrash picture TrashyMcTrash · May 22, 2013 · Viewed 15.6k times · Source

PhantomJS has the option of taking a screenshot of the whole page (not just the current viewport). Is there any way to do so using Selenium? I am running the Cucumber/Capybara tests headlessly, using the headless gem. I would use PhantomJS, but I've had some other problems with it.

Answer

Gabriel Osorio picture Gabriel Osorio · Mar 15, 2016

In case anyone washed up this shore looking for how to do this with Poltergeist you just need to pass the full argument:

page.save_screenshot('screen.png', full: true) # If providing a custom file name.
page.save_screenshot(full: true)               # Capybara sets a name based on timestamp.
page.save_and_open_screenshot('screen.png', full: true) # Same as save_screenshot.
page.save_and_open_screenshot(full: true)               # Same as save_screenshot.

Docs.

Hope it helps!