如何在 Selenium 中使用 Gecko 可执行文件 [英] How to use the gecko executable with Selenium
问题描述
我使用 Firefox 47.0 和 Selenium 2.53.最近,它们是 Selenium 和 Firefox 之间的一个错误,导致代码无法正常工作.解决方案之一是使用 Marionnette 驱动程序.
I'm using Firefox 47.0 with Selenium 2.53. Recently they have been a bug between Selenium and Firefox which make code not working. One of the solution is to use the Marionnette driver.
我按照此网站的说明操作将此新驱动程序与 RemotWebDriver 一起使用,但我一直遇到错误:
I followed the instruction of this site to use this new driver with a RemotWebDriver but I keep having the error :
警告 - 异常:线程main"org.openqa.selenium.WebDriverException 中的异常:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关详细信息,请参阅 https://github.com/jgraham/wires.最新版本可以从...下载.
WARN - Exception: 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 ....
到目前为止我尝试过的代码非常简单:
The code i've tried so far is very simple :
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 的路径是正确的,但我看不出哪里出错了.
I'm sure that the path to the geckodriver.exe is right and i don't see where i did the mistake.
编辑 1:我尝试了以下代码:
EDIT 1: I tried the following code :
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 驱动程序,你们有没有关于它的消息?
and it's working it seems that the problem come from the RemoteWebDriver and the gecko driver, any of you have news on it ?
推荐答案
最近 Selenium 推出了 Selenium 3,如果你想使用 Firefox 最新版本,那么你必须使用 GeckoDriver:
Recently Selenium has launched Selenium 3 and if you are trying to use Firefox latest version then you have to use GeckoDriver:
System.setProperty("webdriver.gecko.driver","G:\Selenium\Firefox driver\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
这篇关于如何在 Selenium 中使用 Gecko 可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!