Taking an IE screenshot returns a black image Taking an IE screenshot returns a black image selenium selenium

Taking an IE screenshot returns a black image


It's because your screen is locked, or a screensaver is running.

You will need to turn off your screensaver and configure windows to never lock itself when not in use. To turn off your screensaver:

  • Click the Start button.
  • Click Control Panel.
  • In the search box, type screen saver.
  • Click Turn screen saver on or off.

Then modify your screensaver settings. Make sure you have unchecked "On resume, display logon screen".

While you're in the control panel it's probably worth checking the power options and making sure the machine isn't going to sleep or powering down after a set period of time as well.

You will also want to use VNC or remote assist to access the GUI. If you RDP in it will lock the screen for the local user who is currently logged in and again it will lock the screen when you disconnect.

Finally don't use the 64-bit IE driver, you should be using the 32Bit one. Nobody runs the 64Bit version of IE (even if they have a 64Bit capable machine).

****** Edit Adding a bit more info from a credible and reputable source ******

Below is a link to a post on the Selenium users forum where Jim Evans (the developer who wrote the IEDriver binaries) explains this:

http://selenium.10932.n7.nabble.com/IE-Screenshots-are-black-when-not-connected-via-Remote-Desktop-to-the-VM-hosting-an-IE-Node-td37004.html

This quote in particular about taking screenshots when you have disconnected from a RDP instance:

It's a known limitation. There is no known workaround. Complain to Microsoft. They're the ones that make the PrintWindow API (which is the proper API to use when grabbing screen captures) behave that way. Either that, or if you discover a way to make it work, you're welcome to submit a patch.

He explains how the screenshot code works in more detail on his blog here:

http://jimevansmusic.blogspot.co.uk/2014/09/screenshots-sendkeys-and-sixty-four.html

Specifically:

The IE driver takes screenshots using the PrintWindow API function. PrintWindow can only take a screenshot of the visible portion of any given window, which means that in order to get a full-page screenshot (as required by the WebDriver API), the window must be sized large enough to display the entire page without scroll bars. However, Windows does not allow the window to be resized larger than the visible screen resolution. When we ask IE to resize itself, a WM_GETMINMAXINFO message is sent on a resize event so the IE can figure how large a window can be. By intercepting that message with a hook, and modifying the max values, we can trick IE into thinking that a window can be sized greater than the screen resolution would otherwise allow.


It looks like this might be a known issue with configuration:

https://code.google.com/p/selenium/issues/detail?id=3536

From what @ShubhasmitGupta mentioned above, it does look like the IE driver hands out black-screen screenshots when the desktop is locked (I'm assuming this has something to do with DWM/Explorer not rendering windows).

There's a workaround involving not locking the targeted computer when connecting to it via RDP. Essentially, you create a disconnect.bat file with the following contents:

tscon rdp-tcp#0 /dest:console

I'm not sure exactly when that's supposed to be run, but the concept is to prevent the test computer from being locked when connecting via Remote Desktop. If that helps, great; I haven't been able to test the workaround myself and figure out how to set it up. Maybe someone else can write a more concise answer.


Open up the Service Control Manager -- You can do WindowsKey+R (run) and type services.msc and hit <ENTER> and it'll start up.

Find the service and right click it and choose properties from the context menu.

Allow Service to Interact With Desktop

Now, select the Log On tab.You want to make sure the checkbox is selected for "Allow service to interact with the desktop".

You can see it in the image below.

Note: I don't have that service so I just picked another one in the sample picture.

enter image description here