selenium-webdriver - 如何在c#上实现PhantomJS + Wedriver

标签 selenium-webdriver phantomjs

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

最佳答案

下载 PhantomJS 或使用 NuGet Package Manager 将其添加到您的项目中。我使用 NuGet 获取它,并且不必将驱动程序的路径作为 PhantomJSDriver 类中的参数之一。

var driver = new PhantomJSDriver();

关于selenium-webdriver - 如何在c#上实现PhantomJS + Wedriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16597125/

相关文章:

c# - 错误 : The Name Assert Does Not Exist In The Current Context

java - Xpath 和 cssselector 在::before 和::after 的情况下似乎不灵活

javascript - phantomjs:document.querySelectorAll() 不适用于动态页面

c# - 如何防止 phantomjs webdriver 耗尽我的所有端口

c# - Selenium Webdriver PhantomJS C# 总是打开一个 cmd 窗口

java - 使用java在Selenium WebDriver中垂直向下滚动和向上滚动

python - 使用 selenium webdriver 切换回父选项卡

javascript - Phantomjs - 引用错误 : Can't find variable: $

python - Selenium:FirefoxProfile 异常无法加载配置文件

javascript - 使用 phantomjs 抓取站点地图