Ответ 1
Клиентские привязки Selenium
попытаются найти исполняемый файл geckodriver
из системы PATH
. Вам нужно будет добавить каталог, содержащий исполняемый файл, к системному пути.
-
В системах Unix вы можете сделать следующее, чтобы добавить его к пути поиска систем, если вы используете bash -совместимую оболочку:
export PATH=$PATH:/path/to/geckodriver
-
В Windows вам необходимо обновить системную переменную Path, чтобы добавить полный путь к исполняемому файлу. Принцип тот же, что и в Unix.
Все приведенные ниже настройки для запуска последней версии firefox с использованием любой привязки языка программирования применимы для Selenium2
, чтобы включить Marionette явно. С Selenium 3.0 и более поздними версиями вам не нужно ничего делать, чтобы использовать Marionette, поскольку она включена по умолчанию.
Чтобы использовать Marionette в своих тестах, вам нужно будет обновить желаемые возможности для ее использования.
Java:
В качестве исключения ясно сказано, что вам нужно скачать последние geckodriver.exe
из здесь и установить загруженный путь geckodriver.exe
, где он существует на вашем компьютере как системное свойство с переменной webdriver.gecko.driver
, прежде чем запускать драйвер марионетки и запустить firefox, как показано ниже: -
//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);
И для 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)
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();
Использование 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)
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);
Примечание. Как и другие драйверы Selenium от других поставщиков браузеров, Mozilla выпустила исполняемый файл, который будет работать вместе с браузером. Для более подробной информации следуйте .
Вы можете скачать последнюю версию geckodriver для поддержки последней версии firefox здесь