我正在使用带有 Selenium 2.53 的 Firefox 47.0。最近,它们成为 Selenium 和 Firefox 之间的一个错误,导致代码无法正常工作。解决方案之一是使用Marionnette 驱动程序。
我按照该 站点 的说明将这个新驱动程序与 RemotWebDriver 一起使用,但我一直遇到错误:
警告 - 异常:线程“main”中的异常 org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关更多信息,请参阅 https://github.com/jgraham/wires 。最新版本可以从….下载。
到目前为止我尝试过的代码非常简单:
public class Test {
static WebDriver driver;
static Wait<WebDriver> wait;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
cap.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://192.168.117.135:5555/wd/hub"), cap);//true to enable the JS
wait = new WebDriverWait(driver, 3000);
final String url = "https://www.google.com/";
JavascriptExecutor js = (JavascriptExecutor) driver;
try {
driver.navigate().to(url);
} finally {
driver.close();
}
}
}
我确定 geckodriver.exe 的路径是正确的,我不知道我在哪里做错了。
编辑1:我尝试了以下代码:
public class Test {
static WebDriver driver;
static Wait<WebDriver> wait;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
driver = new MarionetteDriver();
wait = new WebDriverWait(driver, 3000);
final String url = "https://www.google.com/";
JavascriptExecutor js = (JavascriptExecutor) driver;
try {
driver.navigate().to(url);
} finally {
driver.close();
}
}
}
它的工作似乎问题来自 RemoteWebDriver 和壁虎驱动程序,你们有任何消息吗?
原文由 Robert Reynolds 发布,翻译遵循 CC BY-SA 4.0 许可协议
最近 Selenium 推出了 Selenium 3,如果您尝试使用 Firefox 最新版本,那么您必须使用 GeckoDriver:
您可以从此处查看完整文档