我如何设置属性strictFileInteractability

时间:2019-06-17 11:38:40

标签: selenium firefox selenium-webdriver geckodriver selenium-firefoxdriver

geckodriver 0.24.0引入了功能strictFileInteractability,请参见下文, 但我尚未找到设置此功能的可能性。

代码试用:

FirefoxProfile profile=new FirefoxProfile();

// Has no effect
profile.setPreference("strictFileInteractability", true);

...

FirefoxOptions options = new FirefoxOptions();

// Has no effect
options.setCapability("strictFileInteractability", true);

...

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

// Has no effect
capabilities.setCapability("strictFileInteractability", true);

有人成功设置了此功能吗?

变更日志: github.com/mozilla/geckodriver/releases w3c.github.io/webdriver /

1 个答案:

答案 0 :(得分:1)

GeckoDriver v0.24.0 向我们介绍了strictFileInteractability的功能。

根据WebDriver W3C Living Document中的功能部分:

Capability                  Key                         Value Type  Description
----------                  ---                         ----------  -----------
Strict file interactability "strictFileInteractability" boolean     Defines the current session’s strict file interactability.

根据讨论,Add support for 'strictFileInteractability' W3C capability拉取请求中添加了[java] Adding a type-safe option for strictFileInteractability capability strictFileInteractability功能。


示例

  • 使用 Java Option类和 Firefox

    • 代码块:

      System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
      FirefoxOptions opt = new FirefoxOptions();
      opt.setCapability("strictFileInteractability", true);
      FirefoxDriver driver = new FirefoxDriver(opt);
      driver.get("https://www.google.com/");
      System.out.println(driver.getTitle());
      driver.quit();
      
    • 控制台输出:

      Google
      
  • 使用 Java DesiredCapabilities类和 Firefox

    • 代码块:

      System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
      DesiredCapabilities dc = new DesiredCapabilities();
      dc.setCapability("strictFileInteractability", true);
      FirefoxOptions opt = new FirefoxOptions();
      opt.merge(dc);
      FirefoxDriver driver = new FirefoxDriver(opt);
      driver.get("https://stackoverflow.com");
      System.out.println("Page Title is : "+driver.getTitle());
      driver.quit();
      
    • 控制台输出:

      Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers