【问题标题】:How can i set the Property strictFileInteractability我如何设置属性 strictFileInteractability
【发布时间】:2019-10-31 00:03:07
【问题描述】:

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/

【问题讨论】:

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


    【解决方案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 capabilitystrictFileInteractability 功能是从[java] Adding a type-safe option for strictFileInteractability capability 拉取请求中添加的。


    示例

    • 使用JavaOption 类和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
        
    • 使用 JavaDesiredCapabilities 类和 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
        

    【讨论】:

      猜你喜欢
      • 2018-11-13
      • 2021-12-03
      • 1970-01-01
      • 2011-07-07
      • 2012-04-16
      • 2014-03-11
      • 2019-10-01
      • 2010-09-16
      • 1970-01-01
      相关资源
      最近更新 更多