Selenium 3.6.0&webdriver =新的FirefoxDriver(功能) - 已弃用?

xGI*_*GIx 7 selenium webdriver selenium-webdriver geckodriver

自升级到Selenium的最新版本以来,以下代码似乎已被弃用:

Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated? 
Run Code Online (Sandbox Code Playgroud)

完整代码:

System.setProperty("webdriver.gecko.driver", Base_Page.getConstant(Constant.GECKO_DRIVER_DIRECTORY));
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
webdriver = new FirefoxDriver(capabilities);   //deprecated
Run Code Online (Sandbox Code Playgroud)

Dav*_*tti 11

来自https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES

3.4.1 (2017-06-13)
==================
Firefox:
  * Added new Firefox::Options class that should be used to customize browser
    behavior (command line arguments, profile, preferences, Firefox binary, etc.).
    The instance of options class can be passed to driver initialization using
    :options key. Old way of passing these customization directly to driver
    initialization is deprecated.
Run Code Online (Sandbox Code Playgroud)

从3.4.1版本开始,应该使用FirefoxOptions.


xGI*_*GIx 5

改变后的代码" FirefoxDriver(capabilities),以firefoxOptions它使用.setCapcability()

FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability("marionette", true);
    webdriver = new FirefoxDriver(firefoxOptions);
Run Code Online (Sandbox Code Playgroud)

  • 请添加一些解释您的答案如何解决问题的解释,代码示例帮助,但解释可以帮助其他人理解它的工作原理. (3认同)