在C#中使用PhantomJS获取屏幕截图 [英] Getting screenshot using PhantomJS in C#

查看:98
本文介绍了在C#中使用PhantomJS获取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的C#控制台应用程序中添加了PhantomJS和Selenium,并且我想在浏览器到达特定元素时对其进行截屏.原因是由于某种原因,当我使用ChromeDriver时,它工作正常,但是当我使用PhantomJS时,它在某些元素上失败.

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.

我想我需要介绍如何使用phantomjs在C#中截屏.我在互联网上四处张望,似乎每个人都在使用Java脚本来执行此操作.我遇到的问题是我不知道如何将Java脚本集成到我的C#应用​​程序中,然后将其与phantomJS结合使用以获取屏幕快照.如果我可以得到一些帮助,那就太好了.

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: 我发现 http://code.tutsplus.com/tutorials /testing-javascript-with-phantomjs--net-28243 ,这是我想要做的,但我不知道如何在我的C#应用​​程序中使用javascript.

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.

推荐答案

正如您提到的那样,您已经有适用于Chrome的代码,因此最好将其发布,以显示您的需求.

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.

但是,以下是通常在C#中使用PhantomJSDriver截屏的方法:

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();

请注意,您需要在项目中引用WebDriver.Support.dllSystem.Drawing.

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

这篇关于在C#中使用PhantomJS获取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆