该Selenium
客户端绑定将尝试找到geckodriver
从系统中可执行文件PATH
。您将需要将包含可执行文件的目录添加到系统路径。
在Unix系统上,如果使用的是与bash兼容的shell,则可以执行以下操作将其追加到系统的搜索路径中:
export PATH=$PATH:/path/to/geckodriver
在Windows上,您需要更新Path系统变量以将完整目录路径添加到可执行文件。其原理与Unix相同。
使用任何编程语言绑定来启动最新的firefox的以下所有配置都适用于Selenium2
显式启用Marionette。在Selenium 3.0及更高版本中,您不需要做任何事情来使用木偶,因为它是默认启用的。
要在测试中使用木偶,您将需要更新所需的功能才能使用它。
Java的:
作为例外,很明显,您需要geckodriver.exe
从此处下载最新版本,并geckodriver.exe
使用变量将系统中存在的已下载路径设置为具有变量的系统属性,webdriver.gecko.driver
然后再启动木偶驱动程序并启动Firefox,如下所示:-
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(capabilities);
并Selenium3
用作:-
WebDriver driver = new FirefoxDriver();
如果您仍然遇到问题,请也遵循此链接,这将帮助您解决问题
.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)
红宝石:
# 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();
capabilities.set('marionette', true);
var driver = new webdriver.Builder().withCapabilities(capabilities).build();
使用 RemoteWebDriver
如果要以RemoteWebDriver
任何语言使用,这将允许您Marionette
在Selenium
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)
红宝石:
# 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();
capabilities.setCapability("marionette", true);
WebDriver driver = new RemoteWebDriver(capabilities);
。净
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability("marionette", true);
var driver = new RemoteWebDriver(capabilities);
注意:与其他浏览器供应商提供给Selenium的其他驱动程序一样,Mozilla现在已经发布了一个可执行文件,它将与浏览器一起运行。请遵循此以获取更多详细信息。
您可以从此处下载最新的geckodriver可执行文件以支持最新的Firefox。
selenium 3
一个新问题而发生的,stacktrace也不同。谢谢.. :)