Selenium 2 (webdriver): taking a screenshot returns a black image

I use Selenium 2 (Webdriver) on an ASP.NET website to create a service where users can enter their URL and get screenshots of the page taken using different browsers.

My page is the host on Windows Server 2008 R2.

FirefoxDriver screenshots using FirefoxDriver great. But when I use InternetExplorerDriver , I just get an empty black file.

The application works as an administrator - so there should be no problems with rights.

My code is:

 // Opening the Browser var ieCapabilities = DesiredCapabilities.InternetExplorer(); ieCapabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); var browserIe = new InternetExplorerDriver(ieCapabilities); browserIe.Navigate().GoToUrl("http://www.google.com"); // Screenshot var dir = Server.MapPath("/screenshots/"); browserIe.GetScreenshot().SaveAsFile(dir + "Filename.png", ImageFormat.Png); browserIe.Close(); 

Any ideas why my file is black? THANKS!

+6
source share
2 answers

There is probably nothing wrong with the code. Although, I use Java, so I can’t say for sure.

I had the same issue with IE, while FF and Chrome were working fine.

This post suggests that starting a Selenium server through a remote desktop connection can lead to problems.

Some other reports suggest that the screen saver may have something to do with it.

I just tried disconnecting the remote desktop connection, and it solved the problem with the black screenshot. Also, logging in via VNC seems to work, which leads me to the theory that Windows locks the screen after the remote desktop connection is completed, leaving it unlocked when using VNC.

This message states that disabling screenshots when locking the screen is a Windows security feature.

+5
source
  InternetExplorerDriver mydriver = new InternetExplorerDriver(); mydriver.Navigate().GoToUrl("http://www.google.com/"); Screenshot myScrennShot = ((ITakesScreenshot)iedriver).GetScreenshot(); myScrennShot.SaveAsFile(@"C:\Path\123.png", ImageFormat.Png); //or byte[] data = myScrennShot.AsByteArray; 

It works for me, maybe it works for you too :-) If it doesn’t work, I suggest you split this code into another service (WindowsService), because in this case this problem may be related to application pool restrictions. In any case, please let me know how this happens.

0
source

Source: https://habr.com/ru/post/906594/


All Articles