Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium JavaEclipse-预期浏览器二进制位置_Selenium_Firefox_Testing - Fatal编程技术网

Selenium JavaEclipse-预期浏览器二进制位置

Selenium JavaEclipse-预期浏览器二进制位置,selenium,firefox,testing,Selenium,Firefox,Testing,我正在尝试运行以下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

我正在尝试运行以下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
我正在使用:

Firefox 62.0.2 64位

硒3.3.1

GeckoDriver 0.22.0最新版本

我在这里看过:


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

请尝试下面的代码,并检查您的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();
}}
这应该起作用:

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

64位版本的GeckoDriver。现在它给出以下信息:无法创建新的远程会话。所需功能=功能[{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二进制位置。查看此链接,了解如何设置:与我在前面的评论中提到的相同。org.openqa.selenium.remote.service.DriverCommandExecutor不能强制转换为org.openqa.selenium.firefox.FirefoxDriver$lazycommandexecutor请考虑升级您的selenium版本。我正在使用3.14.0和gecko driver.22.0,以及firefox 62.0.2,并且运行良好。