【问题标题】:Selenium disable FireFox insecure password warningSelenium 禁用 FireFox 不安全密码警告
【发布时间】:2018-01-21 03:24:26
【问题描述】:

我和很多人一样遇到了同样的问题,因为不安全的密码警告,我的测试用例没有在 Firefox 上运行。我从 Stackoverflow 和 Google 尝试了很多“解决方案”,但没有为我解决,所以也许你可以帮助我!

我正在使用网格和 docker 运行 mvn、TestNg、并行测试。我尝试的所有解决方案(Firefox 配置文件、功能...等)都导致远程驱动程序不再启动。

这是我的代码:

public void setUp(String myBrowser) throws MalformedURLException 
{
    driver = new RemoteWebDriver(newURL("http://0.0.0.0:4444/wd/hub"),getBrowserCapabilities(myBrowser));
 }


private static DesiredCapabilities getBrowserCapabilities(String browserType) 
{
      DesiredCapabilities capabillities = null;

    switch (browserType) 
    {
        case "firefox":
            System.out.println("Opening firefox driver");
            capabillities=new DesiredCapabilities().firefox();
            return capabillities;

        case "chrome":
            System.out.println("Opening chrome driver");
            capabillities=new DesiredCapabilities().chrome();
            return capabillities;

        case "IE":
            System.out.println("Opening IE driver");
            capabillities=new DesiredCapabilities().internetExplorer();
            return capabillities;

        default:
            System.out.println("browser : " + browserType + " is invalid, Launching Chrome as browser of choice..");
            capabillities=new DesiredCapabilities().chrome();
            return capabillities;
    }
}

【问题讨论】:

  • 您的代码与您的问题无关?请发布问题的一些屏幕截图,并发布问题发生的代码行
  • 嘿,对不起,我想我描述错了。此代码正在运行,测试用例也在运行。但是我使用的是通过 http 登录,在登录按钮上会弹出这个窗口![密码警告](i.stack.imgur.com/H9uc4.png)。当此窗口弹出时,测试用例因抛出异常而失败,并且测试正在单击登录按钮并打开 Firefox 更多信息选项卡。
  • 所以点击不会出错,但它会打开您想要了解更多信息?
  • 我需要一种方法来禁用不安全的 Firefox 密码警告。我在谷歌上找到的所有东西都不起作用,所以我正在寻找一个适合我发布的代码的解决方案。测试用例在其他浏览器上运行良好。这个显示在了解更多support.mozilla.org/en-US/kb/insecure-password-warning-firefox
  • @TarunLalwani 提到您的代码与您面临的问题无关。根据您面临的问题编辑问题,并提供正确的错误和屏幕截图以供进一步分析。

标签: selenium firefox insecure-connection


【解决方案1】:

您需要创建 Firefox 配置文件并将 security.insecure_password.ui.enabled 设置为 false

FirefoxProfile firefoxProfile=new FirefoxProfile();
firefoxProfile.setPreference("security.insecure_password.ui.enabled",false);
firefoxProfile.setPreference("security.insecure_field_warning.contextual.enabled",false);

WebDriver driver=new FirefoxDriver(firefoxProfile); 

这将确保您不会收到警告

【讨论】:

  • 我会尝试这个解决方案,但是当我在我的代码中构建它时(参见帖子中的代码),驱动程序不再启动。也许我做错了。你知道如何在我的代码结构中设置它吗?
【解决方案2】:

好的,谢谢大家,现在它正在像我想要的那样工作:) 我不太确定为什么,但是有了这个 CodeSnippet,警告就不再出现了。无需更多信息即可设置 Firefox 配置文件。

  capabillities = new DesiredCapabilities().firefox();
  FirefoxProfile profile = new FirefoxProfile();
  capabillities.setCapability(FirefoxDriver.PROFILE , profile);
  return capabillities;

【讨论】:

    【解决方案3】:

    我遇到了类似的问题。将以下代码添加到功能中对我有用。

                FirefoxProfile profile = new FirefoxProfile();
    
                profile.setPreference("pdfjs.disabled", true);
                profile.setPreference("security.insecure_password.ui.enabled", false);
                profile.setPreference("security.insecure_field_warning.contextual.enabled", false);
    
               capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      • 2013-04-03
      相关资源
      最近更新 更多