Selenium: Ability to take full page screenshot

Created on 13 Oct 2015  Â·  11Comments  Â·  Source: SeleniumHQ/selenium

As a follow up from #646, it would be nice if Selenium offered support to take full page screenshots.

Currently, the only way to do this in a consistent manner is to screenshot/pagedown in a loop until page end is reached, then stitch images together. This is a lot of user work, and would be great if Selenium exposed a method which handles this for the user, in all browsers. Although this could be provided as a separate library, it seems to me like the perfect candidate for core inclusion.

Could a maintainer/contributor give their thoughts?

Most helpful comment

I do understand that the spec is screenshot = viewport size, but why not add another like get_full_screenshot_as_file or so?

All 11 comments

At the moment, the intended behavior of the screenshot API _is_ to produce a so-called full page screenshot. In point of fact, the current IE and Firefox drivers _do_ create full page screenshots. Likewise, thr PhantomJS driver also creates full page screenshots. The Chrome driver does view-port-only screenshots, mostly due to a years-old bug in the browser that shows no signs of ever being fixed. Similarly, the Safari driver has architectural limitations imposed by the browser that prevent it from yielding full page screenshots.

While this accurately describes the state of current drivers, the future behavior of drivers will be governed by a W3C specification prescribing behavior of drivers. That spec states outright that screenshots are to be of the current view port only. This decision was discussed at length by the working group responsible for the spec. Any changes in that agreed-upon behavior would need to be taken up with that group.

Moreover, driver implementations are increasingly provided by browser vendors, not the Selenium project. This has been the case for Opera and Chrome for quite some time, recently for Microsoft Edge, and soon to be for Mozilla Firefox. Even if the API provided a way to generate full page screen shots, there's no guarantee that a browser driver, provided by a browser vendor, would support such a command.

Hacks such as scrolling-and-stitching images together seem, on the surface, to be a way forward, but there are too many corner cases where something like that approach fails for a general purpose library like Selenium. A common example is the case of absolutely positioned elements, such as those that remain at the top or bottom of the view port as the user scrolls the page. This is a clear case where scrolling-and-stitching individual screenshots would fail.

Thank you for the detailed response @jimevans, much appreciated

Scroll in the page for capture screenshot is not a solution when the page implement a scroll functionality. The scroll for capture screenshot will affect the aspect page.

Full Page ScreenShot seem to be broken again for latest driver for firefox which is geckoDriver.
Has anybody experienced this?

I have the same problem with gecko driver. Firefox was actually the only driver that I could use for taking screenshot with scroll option (had to downgrade my FF version to 47.0.1). Now I want the same feature for FF 49, and I cannot use other libraries that provide scrolling and stitching screenshots together ... So please reopen and fix this issue asap.

Same here! With this latest stack:
selenium-server-standalone-3.0.0-beta4
geckodriver-v0.11.1-win64
Firefox 49.0.1

I was unable to execute even the basic code of driver.get(url), let alone take screengrab. The only thing that happened was - Firefox browser would open. I had to finally downgrade to 47 to make code work. Definitely some solution will be greatly appreciated.

Also, for the full page screenshot, it is happening only for older Firefox version. IE, Chrome and Edge take view port screengrabs only. I have provided the details on this page: http://newbieshelper.blogspot.com/p/take-screenshot.html

I have not used ‘stitching’, but will look into it and add the details on the above page.

Maybe if we had a method for taking screenshot to a webpage element without cropping the whole page in order to capture the element with located position and crop with its height and width... maybe then we could consider the most external tag like <html> (or something like that) as an element from page and take screenshot to the page?

But even though the specification from webdriver (w3c) has a chapter called Take element screenshot I wasn't able to use it because I think it's not implemented yet.

e.g. For a webElement located with driver.findElement we can use File urlScreenshot = element.getScreenshotAs(OutputType.FILE) ...

Using Firefox 49.0.2 on Linux with Ruby selenium-webdriver 3.0.0 and geckodriver 0.11.1, I can launch the browser and navigate, but screenshots are exactly like they are on modern Chrome - the visible viewport only, and nothing more...

I'm having the same issue as @jantman

I do understand that the spec is screenshot = viewport size, but why not add another like get_full_screenshot_as_file or so?

why not add another like get_full_screenshot_as_file or so?

because the underlying browsers and browser drivers don't support this.

Was this page helpful?
0 / 5 - 0 ratings