我已经编写了以下代码并将 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
}