我已经编写了以下代码并在c:\上指定了文件夹下载了PhantomJS但是我收到错误:“无法连接到远程服务器......”。这是我写的代码:
[TestMethod]
public void HeadlessBrowser()
{
IWebDriver driver = new PhantomJSDriver("C:\\trashStuff\\phantomjs-1.9.0-windows"); //or some other driver
driver.Navigate().GoToUrl("http://yahoo.com");
// Lets take a screenshot to really make sure we did visit the site above
Console.WriteLine("Take A screen shot");
Screenshot myScreenShot = ((ITakesScreenshot)driver).GetScreenshot();
myScreenShot.SaveAsFile("c:\\trashStuff\\screenshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// after the run, go to the location above and find screenshot.jpg
}
答案 0 :(得分:1)
下载PhantomJS或使用NuGet Package Manager
将其添加到您的项目中。我使用NuGet
得到它并且不必将路径作为PhantomJSDriver
类中的参数之一放入驱动程序。
var driver = new PhantomJSDriver();