Getting screenshot using PhantomJS in C# [duplicate]

浪尽此生 提交于 2019-12-28 13:35:13

问题


I have added PhantomJS and Selenium to my C# console app and i want to take a screen shot of the browser when it gets to a specific element. The reason is because for some reason when i use the ChromeDriver it works fine, but when i use PhantomJS it fails on a few elements.

I guess i need an introduction on how to take a screenshot in C# using phantomjs. I have looked around on the internet and it looks like everyone is using java scripts to do this. The problem i am having is i don't know how to integrate the java scripts into my C# app and then use that with phantomJS to get the screen shot. If i can get some help on how to do this it would be very nice.

TLDR: I have 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 the javascript in my c# app.


回答1:


As you mentioned that you have code working for Chrome already, it's better to post it, in order to show what exactly you are after.

However, here is how to take 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();

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



来源:https://stackoverflow.com/questions/24615079/getting-screenshot-using-phantomjs-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!