Firefox selenium webdriver 给出“不安全的连接”

Posted

技术标签:

【中文标题】Firefox selenium webdriver 给出“不安全的连接”【英文标题】:Firefox selenium webdriver gives "Insecure Connection" 【发布时间】:2017-11-26 18:20:45 【问题描述】:

我创建了一个 Maven 项目,其中包含 20 个使用 Selenium Webdriver (java) 进行的测试。现在,当我想执行我的 Maven 项目时,有时会出现以下错误:

Mozilla error

这是由于每次测试都要登录。因此,当我想运行 20 次测试时,有时会出现该错误并且我无法继续我的测试,因此它在 Selenium Webdriver 中返回“Failed test”。

有人知道如何解决这个问题吗? 我试着把“Thread.sleep(30000);”在每次测试结束时给他们一些时间“不要看起来像机器人”,但这不起作用......

非常感谢你们的帮助!

【问题讨论】:

您可以忽略该消息并继续吗? 我该怎么做呢?这是一个新选项卡,它打开并停止测试。我不知道如何忽略它... 好的,你的意思是它没有转到所需的 URL 而是转到此页面(问题中的图像)。然后,您可以尝试更新浏览器和驱动程序并检查 我尝试过:DesiredCapabilities 能力 = DesiredCapabilities.firefox();能力.setCapability(“木偶”,真);能力.acceptInsecureCerts();但它仍然不起作用。我已经更新了浏览器,没有任何新变化。 你也可以试试没有任何想要的功能 【参考方案1】:

这是您问题的答案:

真正的问题:

    如果它是Not Secure,那么当您通过 Mozilla Firefox 53.0 访问该 URL 时,您正在使用的 URL/连接,Firefox 将在地址栏中显示带有红色删除线的红色删除线图标的锁定图标。现在,当 URL 被加载时,默认情况下光标将定位在 Username 字段上,并且会弹出显示消息 This connection is not secure. Logins entered here could be compromised. Learn More,如下所示:

    现在您的脚本通过 Selenium 在Username 输入字段中输入用户名,Not Secure 弹出窗口覆盖Password 输入字段。 接下来,如果您尝试在Password 输入字段中调用click()sendKeys() 操作,Not Secure 弹出窗口会收到点击,Insecure password warning in Firefox 页面会在下一个选项卡中打开,同时 Selenium 会转移其焦点到新标签。因此测试用例开始失败

解决方案:

在这些情况下,最好的解决方案是:

    创建一个新的 Mozilla Firefox 配置文件。您将找到documentation here。例如,我创建了一个名为 debanjan 的 Firefox 配置文件 配置 Firefox 配置文件 debanjan 以忽略所有 UntrustedCertificate 问题。 重新运行您的测试脚本没有任何问题。

    这是禁用insecure_field_warning的示例代码块:

    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    testprofile.setAcceptUntrustedCertificates(true);
    testprofile.setAssumeUntrustedCertificateIssuer(true);
    testprofile.setPreference("security.insecure_field_warning.contextual.enabled", false);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, testprofile);
    dc.setCapability("marionette", true);
    WebDriver driver =  new FirefoxDriver(dc);
    driver.manage().window().maximize();
    driver.navigate().to("http://demosite.center/wordpress/wp-login.php");
    

如果这能回答您的问题,请告诉我。

【讨论】:

这应该可以修复 OP。 你怎么知道这么多?? O_O,它工作得很好。非常感谢你的帮助。你救了我!非常感谢! 我做到了,但由于我是新来的,所以没有显示。但是,我检查了绿色!非常感谢:)

以上是关于Firefox selenium webdriver 给出“不安全的连接”的主要内容,如果未能解决你的问题,请参考以下文章

用于 Firefox 的 Selenium WebDriver [重复]

Selenium w/Firefox 88 更改为 navigator.webdriver

如何隐藏 Firefox 窗口(Selenium WebDriver)?

Selenium Firefox 官方Webdriver -- Geckodriver 下载地址

在 Python 中使用 Selenium WebDriver 时处理 Firefox 无响应?

如何在Firefox 58 ++上使用适用于Selenium的PHP Webdriver下载文件