在PATH中找不到firefox二进制文件.确保安装了firefox

 curzz 发布于 2023-02-06 12:03

在Selenium Grid中我试图执行一个简单的程序,Cannot find firefox binary in PATH虽然我已经在我的代码中添加了二进制路径.
我的代码和错误如下.请帮忙.提前致谢.



package Sample;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class sample1 {
     WebDriver driver;
     String  BaseURL,NodeURL;
@BeforeTest
  public void beforeTest() throws MalformedURLException {
     BaseURL="www.google.com";
     NodeURL="http://192.168.10.162:5566/wd/hub";
     DesiredCapabilities capa =DesiredCapabilities.firefox();
     capa.setBrowserName("firefox");
     capa.setCapability("binary", "C:\\Users\\praveenraj.d\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
     capa.setPlatform(Platform.ANY);
     driver=new RemoteWebDriver(new URL(NodeURL),capa);
  }
   @Test
  public void f() throws InterruptedException {
      driver.get(BaseURL);
      System.out.println(driver.getTitle());
      Thread.sleep(50000);
  }
  @AfterTest
  public void afterTest() {
      driver.quit();
  }
 }


错误

[TestNG] Running:
  C:\Users\praveenraj.d\AppData\Local\Temp\testng-eclipse-1233453386\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeTest beforeTest
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Command duration or timeout: 97 milliseconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
    at Sample.sample1.beforeTest(sample1.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.beforeRun(TestRunner.java:641)
    at org.testng.TestRunner.run(TestRunner.java:609)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.internal.Executable.(Executable.java:72)
    at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:59)
    at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:55)
    at org.openqa.selenium.firefox.FirefoxDriver.getBinary(FirefoxDriver.java:182)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:107)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:216)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:170)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

SKIPPED CONFIGURATION: @AfterTest afterTest
SKIPPED: f

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@93b52b: 27 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3ba002: 22 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@fa930d: 6 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1f9c5c8: 6 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@197f158: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms

小智.. 31

File pathToBinary = new File("C:\\user\\Programme\\FirefoxPortable\\App\\Firefox\\firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();       
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);


Greg Domjan.. 20

另一种选择是配置服务器而不是测试客户端.

配置从属节点服务,以便它知道firefox的位置.安装位置可以在节点之间变化,甚至需要在节点上运行多个服务以支持对不同版本的FF的访问.

java -jar "selenium-server-standalone-2.2.0.jar"
 -Dwebdriver.firefox.bin="C:\FirefoxCollection\Mozilla Firefox 36.0\firefox.exe"


Shubham Jain.. 15

确保firefox必须安装在默认位置,如 - >(c:/ Program Files(x86)/ mozilla firefox或c:/ Program Files/mozilla firefox,注意:在安装firefox时不要改变路径所以让它安装在默认路径中)如果firefox安装在其他地方,那么selenium会显示这些错误.

如果您已在系统(Windows)环境变量中设置firefox,则将其删除或使用新的firefox版本路径更新它.

如果您想在任何其他地方使用Firefox,请使用以下代码: -

由于FirefoxProfile已被删除,我们需要使用如下所示的FirefoxOptions:

新守则:

File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);   
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));

上述代码的完整工作代码如下:

System.setProperty("webdriver.gecko.driver","D:\\Workspace\\demoproject\\src\\lib\\geckodriver.exe");
File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);   
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.co.in/");

从以下URL下载firefox的geckodriver:

https://github.com/mozilla/geckodriver/releases

适用于旧硒罐版本的旧代码

File pathBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();       
WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);

这是有用的信息,它属于Selenium FAQ. (3认同)


donfuxx.. 5

启动selenium服务器后,您是否在路径中添加了firefox?如果是这种情况,selenium仍将使用旧路径.解决方案是拆除重新启动selenium,以便它将使用更新的Path环境变量.

要检查firefox是否正确添加到路径中,您只需启动命令行终端"cmd"并在其中键入"firefox"+ ENTER.如果firefox启动,那么一切都没问题,重新启动selenium服务器应该解决问题.

5 个回答
  • File pathToBinary = new File("C:\\user\\Programme\\FirefoxPortable\\App\\Firefox\\firefox.exe");
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile firefoxProfile = new FirefoxProfile();       
    WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
    

    2023-02-06 12:03 回答
  • 另一种选择是配置服务器而不是测试客户端.

    配置从属节点服务,以便它知道firefox的位置.安装位置可以在节点之间变化,甚至需要在节点上运行多个服务以支持对不同版本的FF的访问.

    java -jar "selenium-server-standalone-2.2.0.jar"
     -Dwebdriver.firefox.bin="C:\FirefoxCollection\Mozilla Firefox 36.0\firefox.exe"
    

    2023-02-06 12:03 回答
  • 我在使用64位Windows和64位Firefox浏览器的C#中遇到了同样的问题,它似乎不适用于Selenium.如果您使用的是64位浏览器,请尝试使用32位浏览器.

    令人惊讶的是,32位Firefox浏览器在64位Windows上运行就好了.

    编辑澄清我的帖子的意图.

    2023-02-06 12:03 回答
  • 确保firefox必须安装在默认位置,如 - >(c:/ Program Files(x86)/ mozilla firefox或c:/ Program Files/mozilla firefox,注意:在安装firefox时不要改变路径所以让它安装在默认路径中)如果firefox安装在其他地方,那么selenium会显示这些错误.

    如果您已在系统(Windows)环境变量中设置firefox,则将其删除或使用新的firefox版本路径更新它.

    如果您想在任何其他地方使用Firefox,请使用以下代码: -

    由于FirefoxProfile已被删除,我们需要使用如下所示的FirefoxOptions:

    新守则:

    File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);   
    DesiredCapabilities desired = DesiredCapabilities.firefox();
    FirefoxOptions options = new FirefoxOptions();
    desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
    

    上述代码的完整工作代码如下:

    System.setProperty("webdriver.gecko.driver","D:\\Workspace\\demoproject\\src\\lib\\geckodriver.exe");
    File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);   
    DesiredCapabilities desired = DesiredCapabilities.firefox();
    FirefoxOptions options = new FirefoxOptions();
    desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
    WebDriver driver = new FirefoxDriver(options);
    driver.get("https://www.google.co.in/");
    

    从以下URL下载firefox的geckodriver:

    https://github.com/mozilla/geckodriver/releases

    适用于旧硒罐版本的旧代码

    File pathBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
    FirefoxProfile firefoxProfile = new FirefoxProfile();       
    WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
    

    2023-02-06 12:03 回答
  • 启动selenium服务器后,您是否在路径中添加了firefox?如果是这种情况,selenium仍将使用旧路径.解决方案是拆除重新启动selenium,以便它将使用更新的Path环境变量.

    要检查firefox是否正确添加到路径中,您只需启动命令行终端"cmd"并在其中键入"firefox"+ ENTER.如果firefox启动,那么一切都没问题,重新启动selenium服务器应该解决问题.

    2023-02-06 12:03 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有