1

I use Selenium (Chrome driver) to generate screenshots of a page. But sometimes the generated screenshot has whitespace in bottom of the screenshot. It happens randomly. It looks like the render just stops (see screenshot attached).

I tried

  • Updated to the latest version of Chrome (60.0.3112.101)
  • Updated to the latest version of Selenium.WebDriver (3.5.1)
  • Disabled "no-sandbox" and "headless" argument

Code

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--headless");
chromeOptions.AddArgument("--no-sandbox");

var driver = new ChromeDriver(Server.MapPath("bin"), chromeOptions, TimeSpan.FromMinutes(3));    
driver.Navigate().GoToUrl("someurl.com");
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(220);
driver.Manage().Window.Size = new Size(4000, 3000);

((ITakesScreenshot)driver).GetScreenshot().SaveAsFile("screenshote.png", ScreenshotImageFormat.Png);

driver.Close();
driver.Quit();

Screenshot

Here is a simple render of a bg image where the render failed. enter image description here

Update

I cannot give a link to the url, but the same url never fails rendering if I use PhantomJS.

Morten OC
  • 1,784
  • 2
  • 23
  • 30

1 Answers1

2

Interesting, I was getting the same problem when using external JAVA library for screenshots, but the problem was that I was taking full page screenshot so scrolling the page was a necessary thing and then screenshots were merged into one with whitespaces. Does not look the same with your case.

I see you're using driver.Manage().Window.Size = new Size(4000, 3000); Perhaps you may try to expand your window in full screen just to see the difference?

I tried to search for external screenshotting frameworks for C# but could not find anyhting :( There are some posts here (ex. 1 or 2) that you might want to check if they contain alternative screenshoting solutions if this bug is critical for your tests. Good luck!

Mykola
  • 352
  • 1
  • 9
  • Thanks for your comment @Mykola! I tried the Full Screen method instead of Size=4000,3000, but it did not work. It's also strange that this happens randomly.. It looks like we have to go back to PhantomJS. – Morten OC Aug 17 '17 at 14:23