Selenium webdriver 如何实现PhantomJS+;Wedriver on c#
我已经编写了以下代码,并将PhantomJS下载到c:\上指定的文件夹中,但收到错误:“无法连接到远程服务器…”。以下是我编写的代码:Selenium webdriver 如何实现PhantomJS+;Wedriver on c#,selenium-webdriver,phantomjs,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().GoTo
[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();
我也是。你能给我们更多的细节吗?上面的代码工作正常。测试正在超时。我添加了以下代码,它起了作用:driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15000));