Selenium - FirefoxDriver不接受代码中的参数

时间:2017-11-15 02:54:03

标签: selenium geckodriver

我无法根据代码使用新FirefoxDriver的参数:

        File pathBinary = new File("C:\\Users\\myname\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
        FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
        FirefoxProfile firefoxProfile = new FirefoxProfile(); 
        WebDriver driver = new FirefoxDriver(firefoxBinary,firefoxProfile);
        //WebDriver driver = new FirefoxDriver();

我收到错误说#34;删除参数以匹配FirefoxProfile();

当我尝试使用新的FirefoxDriver()时,我得到:

        org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8_1

我正在使用:

        geckodriver-v0.19.1-win32
        selenium-server-standalone-3.7.1

最值得赞赏的任何帮助。

1 个答案:

答案 0 :(得分:2)

您需要在Firefox选项中传递它们,请尝试以下

FirefoxProfile ffprofile = new FirefoxProfile();
FirefoxBinary ffBinary = new FirefoxBinary(new File("path to your firefox 
executable"));
FirefoxOptions options = new FirefoxOptions();
options.setProfile(ffprofile);
options.setProfile(ffBinary);
options.setCapability(FirefoxOptions.FIREFOX_OPTIONS,options);
WebDriver driver = new FirefoxDriver(options);