Capturing a screenshot using PhantomJS in C #

I added PhantomJS and Selenium to my C # console application, and I want to take a screenshot of the browser when it hits a specific item. The reason is that for some reason, when I use ChromeDriver, it works fine, but when I use PhantomJS, it doesn't work on multiple elements.

I think I need an introduction on how to take a screenshot in C # using phantomjs. I looked on the Internet and it looks like everyone is using java scripts for this. I have a problem: I don't know how to integrate java scripts into my C # application, and then use this with phantomJS to get a screenshot. If I can get some help on how to do this, it would be very nice.

TL; DR: I found http://code.tutsplus.com/tutorials/testing-javascript-with-phantomjs--net-28243 and this is what I want to do, but I don't know how to use javascript in my C # application.

+7
javascript c # selenium phantomjs selenium-webdriver
source share
1 answer

As you already mentioned that the code for Chrome already works for you, itโ€™s better to place it to show what exactly you are after.

However, here's how to take a screenshot using PhantomJSDriver in C # in general:

 var driver = new PhantomJSDriver(); driver.Manage().Window.Maximize(); // optional driver.Navigate().GoToUrl("http://stackoverflow.com"); driver.TakeScreenshot().SaveAsFile("screenshot.png", ImageFormat.Png); driver.Quit(); 

Please note that you need to reference WebDriver.Support.dll and System.Drawing in your project.

+10
source share

All Articles