【问题标题】:How can i get selenium to ignore chrome insecure forms warning我怎样才能让 selenium 忽略 chrome 不安全表单警告
【发布时间】:2021-03-18 12:14:28
【问题描述】:

我试图让我的测试忽略“站点正在使用不安全的连接”的 chrome 警告消息。

我需要设置什么才能让 webdriver 忽略这个,或者设置 chrome 选项。目前它只是设置为无头。

ChromeOptions co = new ChromeOptions(); co.addArguments("headless","disable-gpu");

我尝试过--allow-running-insecure-content,但这似乎不起作用。

【问题讨论】:

  • 你使用什么语言来运行 selenium? C#?
  • 鉴于addArguments 是用驼峰命名的,我猜java
  • @Jortega 我正在使用 java
  • 所以我知道在 chrome 中我可以在站点设置禁用不安全内容下禁用它,但我想在驱动程序中禁用它。 “allow-running-insecure-content”应该可以工作......但它似乎不起作用

标签: selenium google-chrome webdriver chrome-web-driver


【解决方案1】:

我想你正在寻找--ignore-certificate-errors

co.addArguments("headless","disable-gpu", "--ignore-certificate-errors");

还有:

co.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
co.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

【讨论】:

【解决方案2】:

这可能是由于混合内容,或者如果您在测试中从 https url 导航到 http url,请在 chrome 应用程序数据文件夹中探索 chrome://flags 和 localstate https://blog.chromium.org/2020/08/protecting-google-chrome-users-from.html

OpenQA.Selenium.Chrome.ChromeOptions ops = new OpenQA.Selenium.Chrome.ChromeOptions();
System.Collections.ArrayList expPref = new System.Collections.ArrayList();
expPref.Add("mixed-forms-interstitial@2");     
ops.AddLocalStatePreference("browser.enabled_labs_experiments", expPref);
var service = ChromeDriverService.CreateDefaultService();
var driver = new OpenQA.Selenium.Chrome.ChromeDriver(service, ops, TimeSpan.FromSeconds(60));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多