使用Java的Selenium - 驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置 [英] Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property
问题描述
线程main中的异常java.lang.IllegalStateException :驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置;有关更多信息,请参阅 https://github.com/mozilla/geckodriver 。最新版本可以从 https://github.com/mozilla/geckodriver/releases 下载
我正在使用 Selenium 3.0.01
测试版和 Mozilla 45
。我也尝试过使用 Mozilla 47
。但仍然是一样的。
绑定将尝试从系统 PATH
中找到 geckodriver
可执行文件。
$ b
-
在 Unix 系统,如果您使用兼容bash的shell,您可以执行以下操作将其附加到系统的搜索路径:
export PATH = $ PATH:/ path / to / geckodriver
-
> Windows ,您需要更新Path系统变量以将完整的目录路径添加到可执行文件。原理与Unix相同。
以下所有使用任何编程语言启动Firefox的配置绑定适用于
Selenium2
来明确地启用Marionette。使用Selenium 3.0和更高版本,你不需要做任何事情就可以使用Marionette,因为它默认是启用的。
使用Marionette您的测试,您将需要更新所需的功能来使用它。
Java :
例外情况显然是说你需要从 geckodriver.exe / releaserel =noreferrer>这里,并将下载的
geckodriver.exe
路径作为系统属性存在于您的计算机中,其中变量webdriver.gecko.driver
,然后启动木偶驱动程序并启动firefox,如下所示:
/ /如果你没有更新Path系统变量来将完整的目录路径添加到可执行文件,那么直接通过代码
System.setProperty(webdriver.gecko.driver,path / to / geckodriver.exe);
//现在你可以初始化marionette驱动来启动firefox
DesiredCapabilities功能= DesiredCapabilities.firefox();
capabilities.setCapability(marionette,true);
WebDriver driver = new MarionetteDriver(capabilities);
而对于
Selenium3
/ p>
WebDriver driver = new FirefoxDriver();
.NET :
var driver = new FirefoxDriver(new FirefoxOptions()) ;
Python :
from selenium import webdriver
/ pre>
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
#告诉Python绑定使用Marionette。
#这将不再是必要的,
#当Selenium将自动检测到它正在与哪个远端的
#通话。
caps [marionette] = True
#Firefox DevEdition或Nightly的路径。
#目前不支持Firefox 47(stable),
#,可能会给你一个不太理想的体验。
#
#在Mac OS上,您必须指向应用程序包内的二进制可执行文件
#,如
#/Applications/FirefoxNightly.app/Contents/MacOS/firefox- bin
caps [binary] =/ usr / bin / firefox
driver = webdriver.Firefox(capabilities = caps)
Ruby :
#Selenium 3默认使用木偶,当指定firefox的时候
#通过直接传递木偶在Selenium 2中设置木偶:true
#你可能需要指定一个所需版本的Firefox的替代路径
Selenium :: WebDriver :: Firefox :: Binary.path =/ path / to / firefox
driver = Selenium :: WebDriver.for:firefox,marionette:true
$ bJavaScript(Node.js):
const webdriver = require('selenium-webdriver');
const Capabilities = require('selenium-webdriver / lib / capabilities')。
var capabilities = Capabilities.firefox();
//告诉Node.js绑定使用Marionette。
//这将不是必要的,
当Selenium会自动检测远端
正在与哪个对话。
capabilities.set('marionette',true);
var driver = new webdriver.Builder()。withCapabilities(capabilities).build();
使用RemoteWebDriver
如果您想以任何语言使用
RemoteWebDriver
,这将允许您使用Marionette 在
Selenium
表格中。
$ bPython :
caps = DesiredCapabilities.FIREFOX
#告诉Python绑定使用Marionette。
#这将不再是必要的,
#当Selenium将自动检测到它正在与哪个远端的
#通话。
caps [marionette] = True
driver = webdriver.Firefox(capabilities = caps)
Ruby :
#Selenium 3默认使用Marionette firefox被指定为
#通过使用Capabilities类来设置Selenium 2中的Marionette
#您可能需要为所需的Firefox版本指定一个备用路径
caps = Selenium :: WebDriver :: Remote :: Capabilities.firefox marionette:true,firefox_binary:/ path / to / firefox
driver = Selenium :: WebDriver.for:remote,desired_capabilities:caps
$ c $
DesiredCapabilities功能= DesiredCapabilities.firefox();
//告诉Java绑定使用Marionette。
//这将不是必要的,
当Selenium会自动检测远端
正在与哪个对话。
capabilities.setCapability(marionette,true);
WebDriver驱动程序=新的RemoteWebDriver(功能);
.NET
DesiredCapabilities功能= DesiredCapabilities.Firefox();
//告诉.NET绑定使用Marionette。
//这将不是必要的,
当Selenium会自动检测远端
正在与哪个对话。
capabilities.SetCapability(marionette,true);
var driver = new RemoteWebDriver(capabilities);注意:就像其他浏览器供应商提供给Selenium的其他驱动程序一样,Mozilla现在已经发布了一个可执行文件这将与浏览器一起运行。按照这个了解更多详情。
你可以从这里下载最新的geckodriver可执行文件来支持最新的Firefox。
I am trying to launch Mozilla but still I am getting this error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
I am using
Selenium 3.0.01
Beta version andMozilla 45
. I have tried withMozilla 47
too. but still the same thing.解决方案The
Selenium
client bindings will try to locate thegeckodriver
executable from the systemPATH
. You will need to add the directory containing the executable to the system path.On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/geckodriver
On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.
All below configuration for launching latest firefox using any programming language binding is applicable for
Selenium2
to enable Marionette explicitly. With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.To use Marionette in your tests you will need to update your desired capabilities to use it.
Java :
As exception is clearly saying you need to download latest
geckodriver.exe
from here and set downloadedgeckodriver.exe
path where it's exists in your computer as system property with with variablewebdriver.gecko.driver
before initiating marionette driver and launching firefox as below :-//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe"); //Now you can Initialize marionette driver to launch firefox DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); WebDriver driver = new MarionetteDriver(capabilities);
And for
Selenium3
use as :-WebDriver driver = new FirefoxDriver();
If you're still in trouble follow this link as well which would help you to solving your problem
.NET :
var driver = new FirefoxDriver(new FirefoxOptions());
Python :
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities caps = DesiredCapabilities.FIREFOX # Tell the Python bindings to use Marionette. # This will not be necessary in the future, # when Selenium will auto-detect what remote end # it is talking to. caps["marionette"] = True # Path to Firefox DevEdition or Nightly. # Firefox 47 (stable) is currently not supported, # and may give you a suboptimal experience. # # On Mac OS you must point to the binary executable # inside the application package, such as # /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin caps["binary"] = "/usr/bin/firefox" driver = webdriver.Firefox(capabilities=caps)
Ruby :
# Selenium 3 uses Marionette by default when firefox is specified # Set Marionette in Selenium 2 by directly passing marionette: true # You might need to specify an alternate path for the desired version of Firefox Selenium::WebDriver::Firefox::Binary.path = "/path/to/firefox" driver = Selenium::WebDriver.for :firefox, marionette: true
JavaScript (Node.js) :
const webdriver = require('selenium-webdriver'); const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities; var capabilities = Capabilities.firefox(); // Tell the Node.js bindings to use Marionette. // This will not be necessary in the future, // when Selenium will auto-detect what remote end // it is talking to. capabilities.set('marionette', true); var driver = new webdriver.Builder().withCapabilities(capabilities).build();
Using
RemoteWebDriver
If you want to use
RemoteWebDriver
in any language, this will allow you to useMarionette
inSelenium
Grid.Python:
caps = DesiredCapabilities.FIREFOX # Tell the Python bindings to use Marionette. # This will not be necessary in the future, # when Selenium will auto-detect what remote end # it is talking to. caps["marionette"] = True driver = webdriver.Firefox(capabilities=caps)
Ruby :
# Selenium 3 uses Marionette by default when firefox is specified # Set Marionette in Selenium 2 by using the Capabilities class # You might need to specify an alternate path for the desired version of Firefox caps = Selenium::WebDriver::Remote::Capabilities.firefox marionette: true, firefox_binary: "/path/to/firefox" driver = Selenium::WebDriver.for :remote, desired_capabilities: caps
Java :
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); // Tell the Java bindings to use Marionette. // This will not be necessary in the future, // when Selenium will auto-detect what remote end // it is talking to. capabilities.setCapability("marionette", true); WebDriver driver = new RemoteWebDriver(capabilities);
.NET
DesiredCapabilities capabilities = DesiredCapabilities.Firefox(); // Tell the .NET bindings to use Marionette. // This will not be necessary in the future, // when Selenium will auto-detect what remote end // it is talking to. capabilities.SetCapability("marionette", true); var driver = new RemoteWebDriver(capabilities);
Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released now an executable that will run alongside the browser. Follow this for more details.
You can download latest geckodriver executable to support latest firefox from here
这篇关于使用Java的Selenium - 驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!