【问题标题】:How can I use setExperimentalOption through Options using FirefoxDriver in Selenium IDE?如何在 Selenium IDE 中通过使用 FirefoxDriver 的选项使用 setExperimentalOption?
【发布时间】:2020-10-14 14:27:52
【问题描述】:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));

我想使用 Selenium IDE 登录 Google,但 Google 不允许自动化框架登录。但是,通过使用上述选项,可以登录 Google。

以上选项是为ChromeDriver 定义的,我需要为FirefoxDriver 定义它们。我该怎么做?

【问题讨论】:

    标签: java selenium selenium-chromedriver selenium-ide selenium-firefoxdriver


    【解决方案1】:

    从每一天开始,GeckoDriverChromeDriver 都在不断发展,变得更加强大并符合 WebDriver Level 2 W3C 规范。

    但是,通过ChromeOptionsFirefoxOptions 支持的方法还是有点不同。

    FirefoxOptions() 支持的方法

    • addArguments(addArguments(java.lang.String... arguments)
    • addPreference(java.lang.String key, java.lang.String value)
    • merge(Capabilities capabilities)
    • setCapability(java.lang.String key, java.lang.Object value)
    • setHeadless(boolean headless)
    • setLegacy(boolean legacy)
    • setLogLevel(FirefoxDriverLogLevel logLevel)
    • setPageLoadStrategy(PageLoadStrategy strategy)
    • setProfile(FirefoxProfile profile)
    • setProxy(Proxy proxy)
    • setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour)

    ChromeOptions()支持的方法

    • addArguments(java.lang.String... arguments)
    • addExtensions(java.io.File... paths)
    • addEncodedExtensions(java.util.List<java.lang.String> encoded)
    • merge(Capabilities extraCapabilities)
    • setBinary(java.lang.String path)
    • setExperimentalOption(java.lang.String name, java.lang.Object value)
    • setHeadless(boolean headless)
    • setPageLoadStrategy(PageLoadStrategy strategy)
    • setProxy(Proxy proxy)
    • setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour)

    因此很明显,虽然ChromeOptions()FirefoxOptions() 支持的方法几乎相似,但它们各自支持一些不同的方法。 setExperimentalOption(java.lang.String name, java.lang.Object value) 就是其中之一。


    setExperimentalOption()

    setExperimentalOption(java.lang.String name, java.lang.Object value) 设置实验选项。此方法对于尚未通过 ChromeOptions API 公开的新 ChromeDriver 选项很有用。

    public ChromeOptions setExperimentalOption(java.lang.String name, java.lang.Object value)
    

    结论

    setExperimentalOption() 方法仅通过 ChromeOptions() 独家支持,不通过 FirefoxOptions() 支持。

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2019-04-18
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      相关资源
      最近更新 更多