使用 Java 的 Selenium - 驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置 [英] Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property

查看:23
本文介绍了使用 Java 的 Selenium - 驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启动 Mozilla,但仍然出现此错误:

I am trying to launch Mozilla but still I am getting this error:

线程main"中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关详细信息,请参阅 https://github.com/mozilla/geckodriver.最新版本可从https://github.com/mozilla/geckodriver/releases

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

我使用的是 Selenium 3.0.01 Beta 版和 Mozilla 45.我也尝试过 Mozilla 47.但还是一样.

I am using Selenium 3.0.01 Beta version and Mozilla 45. I have tried with Mozilla 47 too. but still the same thing.

推荐答案

Selenium 客户端绑定将尝试从系统 geckodriver 可执行文件>路径.您需要将包含可执行文件的目录添加到系统路径中.

The Selenium client bindings will try to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.

  • Unix 系统上,如果您使用与 bash 兼容的 shell,您可以执行以下操作将其附加到系统的搜索路径:

  • 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

  • Windows 上,您需要更新 Path 系统变量以将完整目录路径添加到可执行文件.原理和Unix一样.

  • 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.

    使用任何编程语言绑定启动最新的 firefox 的所有以下配置都适用于 Selenium2 以显式启用 Marionette.在 Selenium 3.0 及更高版本中,您无需执行任何操作即可使用 Marionette,因为它默认处于启用状态.

    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.

    要在测试中使用 Marionette,您需要更新所需的功能才能使用它.

    Java:

    作为例外,您需要从 此处下载最新的 geckodriver.exe 并将下载的 geckodriver.exe 路径设置为您计算机中存在的系统属性,并在启动 marionette 驱动程序并启动 firefox 之前使用变量 webdriver.gecko.driver下面:-

    As exception is clearly saying you need to download latest geckodriver.exe from here and set downloaded geckodriver.exe path where it's exists in your computer as system property with with variable webdriver.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); 
    

    对于 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();
    
    // 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,这将允许您在 Selenium 网格中使用 Marionette.

    If you want to use RemoteWebDriver in any language, this will allow you to use Marionette in 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();
    
    // 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 现在发布了一个可以与浏览器一起运行的可执行文件.关注this了解更多详情.

    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.

    您可以从这里下载最新的 geckodriver 可执行文件以支持最新的 firefox

    这篇关于使用 Java 的 Selenium - 驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆