3

我已经编写了以下代码并将 PhantomJS 下载到 c:\ 上的指定文件夹中,但出现错误:“无法连接到远程服务器 ...”。这是我写的代码:

[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
}
4

1 回答 1

1

下载 PhantomJS 或使用NuGet Package Manager. 我使用它NuGet并且不必将驱动程序的路径作为PhantomJSDriver类中的参数之一。

var driver = new PhantomJSDriver();
于 2014-11-12T23:10:27.357 回答