提问人:Sankar 提问时间:9/26/2023 最后编辑:TylerHSankar 更新时间:9/29/2023 访问量:47
C# Selenium ChromeDriverService 在 Windows 11 操作系统上抛出 SSL 相关错误以加载网站
C# Selenium ChromeDriverService throwing SSL related error on windows 11 OS for loading web site
问:
我有一个小的 c# 控制台程序,它使用 Selenium 逐个加载 URL 列表并解析一些文本数据。我们的程序在 Windows 10 操作系统上成功运行,但在 Windows 11 操作系统上运行我的程序时,收到以下错误消息:
从错误图像来看,错误似乎与SSL有关,但不确定。
我正在分享我的一些代码,即我如何使用 chrome 加载网站。
string _dowLoginUrl = "https://newsplus.wsj.com/";
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("headless");
chromeOptions.Proxy = null;
ChromeDriverService chromeservice = ChromeDriverService.CreateDefaultService(_chromeDriver);
chromeservice.HideCommandPromptWindow = true;
Idriver = new ChromeDriver(chromeservice, chromeOptions);
Idriver.Manage().Cookies.DeleteAllCookies();
Idriver.Navigate().GoToUrl(Url);
System.Threading.Thread.Sleep(4000);
以这种方式以编程方式登录到站点
var loginBox = Idriver.FindElement(By.XPath("//input[@id='email']"));
loginBox.SendKeys("[email protected]");
var pwBox = Idriver.FindElement(By.XPath("//input[@id='password']"));
pwBox.SendKeys("password123");
var signinBtn = Idriver.FindElement(By.ClassName("basic-login-submit"));
signinBtn.Click();
- 为了克服这个问题,我以这种方式使用了ServicePointManager
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback +=
(sender, cert, chain, error) =>
{
return true;
};
添加上述行后,我收到相同的错误消息。
我的第二次尝试如下
我稍后添加此 chrome 选项
chromeOptions.AddArguments("ignore-certificate-errors");
但仍然没有运气;我有同样的错误消息。
我需要在 Windows 11 的设置中设置或更改什么?
答: 暂无答案
评论
var loginBox = Idriver.FindElement(By.XPath("//input[@id='email']")); loginBox.SendKeys("[email protected]"); var pwBox = Idriver.FindElement(By.XPath("//input[@id='password']")); pwBox.SendKeys("password123"); Main code updated