我使用的是 Firefox 47.0 和 Selenium 2.53。最近,Selenium 和 Firefox 之间出现了一个 bug,导致代码无法运行。解决方案之一是使用 Marionnette 驱动程序。
我按照这个指示site https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver将这个新驱动程序与 RemotWebDriver 一起使用,但我仍然遇到错误:
警告 - 异常:线程“main”org.openqa.selenium.WebDriverException 中出现异常:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关更多信息,请参阅https://github.com/jgraham/wires 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 和 gecko 驱动程序,你们中有人有这方面的消息吗?