0

I am using selenium web driver 3.4.0. I have downloaded IEDriver.exe and copied to bin folder. I have an MVC application which will be working on taking the screenshot for given link. The link can be anything for any website. We need to take the screenshot for that webpage and store that into the PDF. Now, I have created the console application using C# and added WebDriver.dll. The application works fine when console application is called. The screenshot is taken.

When same code is called from the MVC web application, its taking the screenshot for web page but its black. Is there any reason for this?

var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

var driver = new InternetExplorerDriver(options);

driver.Manage().Window.Maximize();

driver.Navigate().GoToUrl("URL TO BE BROWSED");

var screenshot = ((ITakesScreenshot)driver).GetScreenshot();   

screenshot.SaveAsFile("Test.png", ScreenshotImageFormat.Png);
driver.Quit();
  • Does this comment help? https://stackoverflow.com/questions/17347451/how-can-i-take-a-screenshot-of-a-website-with-mvc (see the STA part) – Nir Feb 05 '18 at 11:37
  • This will not work in out case. We have already tried the WebBrowser option. I guess it does not allow you to specify the proxy details. – Raju Wagh Feb 05 '18 at 13:57
  • typically, the browser offloads redering PDF's to the adobe control and not by the browser itself. if you have a pdf why not save the entire pdf instead of trying to screenshot it. – Fran Feb 05 '18 at 16:41
  • We need to get the screenshot for multiple webpages and then read stream from images (we will not store anything on server. we will only read stream) and add it to PDF. – Raju Wagh Feb 08 '18 at 06:23

1 Answers1

0

Does it open the webpage at all? If not, make sure you have the correct IEDriverServer.exe. Also, if you are calling Selenium from inside the controller, you need to map the output, like screenshot.SaveAsFile(Server.MapPath("Test.png"), ScreenshotImageFormat.Png); but that would mean your MVC Web App is opening a browser window on your server & going to some other website; I don't know if that is what you want or not.

William
  • 491
  • 5
  • 9