当前位置: 首页 > 知识库问答 >
问题:

使用Java硒-驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置

姬寂离
2023-03-14

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

线程“main”java中出现异常。lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver设置。壁虎。驱动系统属性;有关更多信息,请参阅https://github.com/mozilla/geckodriver.最新版本可从以下网站下载:https://github.com/mozilla/geckodriver/releases

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

共有3个答案

和和裕
2023-03-14

Selenium WebDriver Java代码:

从下载Gecko驱动程序https://github.com/mozilla/geckodriver/releases基于你的平台。根据您的选择在某个位置提取。编写以下代码:

System.setProperty("webdriver.gecko.driver", "D:/geckodriver-v0.16.1-win64/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.lynda.com/Selenium-tutorials/Mastering-Selenium-Testing-Tools/521207-2.html");
严升
2023-03-14
  1. 从seleniumhq网站下载gecko驱动程序(现在它在GitHub上,你可以从这里下载)。
    1. 你会有一个拉链(或tar.gz),所以把它取出来
    2. 提取后你会得到壁虎河。exe文件(linux中适当的可执行文件)
    3. 在C中创建文件夹:名为SeleniumGecko(或适当的)
    4. 复制并粘贴geckodriver。exe到SeleniumGecko
    5. 设置gecko驱动程序的路径如下

    .

    System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    

高琛
2023-03-14

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

>

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

    export PATH=$PATH:/path/to/geckodriver
    

    在Windows上,您需要更新Path系统变量以将完整目录路径添加到可执行文件中。原理与Unix相同。

    下面所有使用任何编程语言绑定启动最新firefox的配置都适用于Selenium2以明确启用木偶。在Selenium 3.0及更高版本中,您不需要做任何事情来使用木偶,因为它在默认情况下是启用的。

    要在测试中使用木偶,您需要更新所需的功能以使用它。

    Java:

    作为例外,你需要下载最新的geckodriver。exe从这里下载并设置geckodriver。exe路径,它作为系统属性存在于您的计算机中,带有变量webdriver。壁虎。驱动程序在启动木偶驱动程序并启动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());
    

    蟒蛇:

    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

    蟒蛇:

    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); 
    

    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

  •  类似资料: