c#-chromedriver-忽略证书错误
我正在尝试将ChromeDriver 2.4.226107与Selenium 2.45、Google Chrome 42.0.2311.135、Visual Studio 2012和.NET 4.5一起使用。我的小测试应用程序可以编译并运行,但当它启动一个新的Chrome窗口时,我会遇到以下错误:c#-chromedriver-忽略证书错误,c#,selenium,selenium-webdriver,selenium-chromedriver,C#,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在尝试将ChromeDriver 2.4.226107与Selenium 2.45、Google Chrome 42.0.2311.135、Visual Studio 2012和.NET 4.5一起使用。我的小测试应用程序可以编译并运行,但当它启动一个新的Chrome窗口时,我会遇到以下错误: "You are using an unsupported command-line flag: --ignore-certifiate-errors. Stability and security
"You are using an unsupported command-line flag: --ignore-certifiate-errors. Stability and security will suffer."
我仔细阅读并尝试了许多建议的修复方法,但没有任何效果。我一次又一次看到的一个建议解决方案是:
options.AddArgument("test-type");
这与Chrome 42.0没有任何关系。这是我的C代码(控制台应用程序):
黄色条内有错误的Chrome窗口如下所示:
我不知道发生了什么,但今天早上突然之间,一切都很顺利。昨晚同样的代码不起作用。无论如何,如果它对任何人都有帮助,下面是chromedriver 2.5、.NET 4.5和Selenium 2.45二进制文件的C#代码:
static void Main(string[] args) {
ChromeOptions options = new ChromeOptions();
options.AddArgument("test-type");
// Initialize the Chrome Driver
using(var driver = new ChromeDriver(options)) {
driver.Navigate().GoToUrl("http://localhost/test.aspx");
// Get User Name field, Password field and Login Button
var userNameField = driver.FindElementById("txtUsername");
var userPasswordField = driver.FindElementById("txtPassword");
var loginButton = driver.FindElementById("btnLogin");
// Type user name and password
userNameField.SendKeys("MyUSN");
userPasswordField.SendKeys("MyPWD");
// and click the login button
loginButton.Click();
// Take a screenshot and save it into screen.png
driver.GetScreenshot().SaveAsFile(@"F:\temp\screen.png", ImageFormat.Png);
Console.ReadLine();
}
}
注意:要在所有测试中重复使用相同的Chrome浏览器窗口,请创建一个静态类变量:
private static ChromeDriver driver;
(实际上,您可能希望使所有类级变量都是静态的。)
然后执行如下操作,以便ChromeDriver的句柄可以在所有测试中重用:
[ClassInitialize] // this only executes ONCE per test-run (not once per test!)
public static void OneTimeSetup(TestContext ctxt) {
ChromeOptions options = new ChromeOptions();
options.AddArgument("test-type");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;
driver = new ChromeDriver(@"C:\MyStuff", options);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4));
}
[ClassInitialize] // this only executes ONCE per test-run (not once per test!)
public static void OneTimeSetup(TestContext ctxt) {
ChromeOptions options = new ChromeOptions();
options.AddArgument("test-type");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;
driver = new ChromeDriver(@"C:\MyStuff", options);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4));
}