问题描述
我正在尝试让我的测试忽略“站点正在使用不安全的连接”的 chrome 警告消息。
我需要设置什么才能让 webdriver 忽略这个,或者设置 chrome 选项。目前它只是设置为无头。
ChromeOptions co = new ChromeOptions(); co.addArguments("headless","disable-gpu");
我试过 --allow-running-insecure-content
但这似乎不起作用。
解决方法
我认为您正在寻找--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);
,
这可能是由于混合内容,或者如果您在测试中从 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));