I am downloading a pdf file with Selenium browser and I need a screenshot of it. The simplest method that I thought was to open it in the browser (Chrome) and take a screenshot with the driver. But, the issue is that the screenshot is empty, with a gray background
Am I missing something? Isn’t Selenium Chromedriver able to take a screenshot of a file opened in browser?
Some code that I use:
driver.SwitchTo().NewWindow(WindowType.Tab);
Thread.Sleep(1000);
driver.Navigate().GoToUrl(file);
ITakesScreenshot screenshot = driver as ITakesScreenshot;
Screenshot screenshotObj = screenshot.GetScreenshot();
screenshotObj.SaveAsFile(filePath, ScreenshotImageFormat.Png);
>Solution :
Remember that Selenium operates asynchronously in real-time. GoToUrl returns long before the file has been received. You might add a multi-second sleep and see if that helps things.