我正在使用Firefox 47.0和Selenium 2.53。最近,Selenium和Firefox之间出现了一个bug,导致代码无法正常运行。其中一个解决方案是使用Marionnette驱动程序。
我按照这个网站的说明使用了新的驱动程序来创建RemotWebDriver,但我一直遇到以下错误:
警告 - 异常:Exception in thread "main" org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from ....
我尝试过的代码非常简单:
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驱动程序,你们有任何消息吗?