0

Question and answers on Take a screenshot with Selenium WebDriver contain excellent description how to take screen shot with Selenium Web Driver using different languages.

I drive my Web Driver with Python and C# and with a set of different browser drivers.

For example if screenshot is taken with PhantomJS headless browser with Python, I get full page shot.

In C# screenshot is not directly provided as a driver method, so a bit of code is needed (see above mentioned question and suggested C# solution).

However, C# recipe albeit working perfectly taking a screen shot, is not what I am looking for.

The problem is that C# recipe takes a screen shot, and what I am looking for is how to take a full page shot. Screen shot is expected to be what is seen on the screen, and browser pages are often larger than the screen. In many cases a shot taken shall be page shot.

This question differ than quoted one in subtle question detail that makes difference in the result. I guess that solutions for page shoot for different languages would be welcome here.

Community
  • 1
  • 1
ljgww
  • 3,418
  • 6
  • 19
  • 21
  • 2
    i think the only way around this is to set the size of your browser window in code. that way, the screenshot is directly related to the canvas size. here's what may help in your driver instantiation: `_driver.Manage().Window.Size = new System.Drawing.Size(1280, 5000); ` (or some arbitary big height!!) – jim tollan Apr 23 '15 at 07:41
  • driver.Manage().Window.Size sets a physical window size (I use this to change window size on some browsers that has fairly small windows when webdriver starts). When page is longer/wider than the page, I would assume canvas is also larger as content gets scroll bars. Will try this recipe and reflect. – ljgww Apr 24 '15 at 07:40

1 Answers1

4

Screenshots in the current WebDriver API are defined as full-page screenshots. When you take a screenshot via WebDriver, you should be getting them of the full page, no matter what language (Python, C#, Java, etc.) you use. Having said that, there are some caveats to note.

For the IE driver, if you run on 64-bit Windows, and use the 32-bit IEDriverServer.exe, you'll see your screenshots truncated to the maximum size of the display resolution of the system, with any overflow as black portions of the image. This is due to the limitations of Windows hook procedures that are used to allow the IE driver to create full-page screenshots. More in-depth detail can be found in a blog post by the author of the IE driver.

The driver for Chrome only provides screenshots of the visible view port. This is a known issue of the driver, and has been for some time, and cannot be fixed due to an underlying bug in the Chrome browser itself.

The architecture of the Safari driver doesn't allow for full-DOM screenshots. Due to the limited nature of the extension points provided by the Safari browser, it's unlikely this will change.

Finally, all of this discussion about screenshots is only relevant to current WebDriver implementations. The W3C working group creating a WebDriver spec has decided that screenshots should only be of the visible view port, so this behavior will likely change in the future, and only allow screenshots of the view port.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • Thank you very much for this in-depth insight. – ljgww Apr 24 '15 at 07:43
  • 2
    +1 jim... so many nuggets of info in this answer. i completely *get* why the W£C group would opt to only show the viewport by default. perhaps this would allow for further extensions to screenshot the entire canvas explicitly, thereby standardising the behaviours across browsers. – jim tollan Apr 24 '15 at 07:45
  • From the battlefield. Tried IE9, FF37 and Chrome 42 - FF and IE take a full canvas shot. Chrome gets the visible part. Will try more of them. Just wanted to endorse Jim's answer as excellent guide line when pondering cross browser capabilities. – ljgww Apr 27 '15 at 06:47