【问题标题】:Java Eclipse - Expect browser binary locationJava Eclipse - 期望浏览器二进制位置
【发布时间】:2019-03-06 08:53:22
【问题描述】:

我正在尝试运行以下 Java 代码:

package tests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class sekcija9 {

    public static void main(String[] args) {        
        System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
    }
}

我收到以下错误:

Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

我正在使用:

  1. 火狐62.0.2 64位

  2. 硒 3.3.1

  3. GeckoDriver 0.22.0(最新)

我看过这里:link

我需要降级 Firefox 版本吗?如果没有,如何在不降级的情况下解决此问题?

【问题讨论】:

  • 考虑升级您的 selenium 版本。我正在使用 3.14.0 和 gecko 驱动程序 .22.0 和 firefox Firefox 62.0.2 ,它工作正常。

标签: selenium firefox testing


【解决方案1】:

试试下面的代码,并检查你的 Firefox 版本是否与 Gecko 驱动程序兼容。

   import org.openqa.selenium.Platform;
   import org.openqa.selenium.WebDriver;
   import org.openqa.selenium.firefox.FirefoxDriver;
   import org.openqa.selenium.remote.DesiredCapabilities;
   public class geckodriver {
       public static void main(String[] args) throws InterruptedException {

             System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
           Thread.sleep(5000);
//           DesiredCapabilities capabilities = DesiredCapabilities.firefox();
//            capabilities.setCapability("marionette", true);
//           
//           WebDriver driver = new FirefoxDriver(capabilities);

           DesiredCapabilities capabilities = new DesiredCapabilities();

           capabilities = DesiredCapabilities.firefox();
           capabilities.setBrowserName("firefox");
           capabilities.setVersion("your firefox version");
           capabilities.setPlatform(Platform.WINDOWS);
           capabilities.setCapability("marionette", false);

           WebDriver driver = new FireFoxDriver(capabilities);

             driver.get("http://www.google.com");

             Thread.sleep(5000);
             driver.quit();
}}

【讨论】:

  • GeckoDriver 的 64 位版本。
  • 现在它给出了以下信息:无法创建新的远程会话。所需功能 = 功能 [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}],所需功能 = 功能 [{moz: firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}]
  • 您需要提供 Firefox 二进制位置。查看此链接以了解如何设置它。 :automationtestinghub.com/…
  • 和我在上一条评论中提到的一样。
  • org.openqa.selenium.remote.service.DriverCommandExecutor 无法转换为 org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
【解决方案2】:

这应该可行:

public static void main(String[] args) {        
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver(options);
        driver.get("http://www.google.com");
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-31
    • 2021-07-18
    • 1970-01-01
    • 2021-09-22
    • 2021-03-02
    • 2021-05-06
    • 1970-01-01
    • 2022-06-29
    相关资源
    最近更新 更多