C# Selenium ChromeDriverService 在 Windows 11 操作系统上抛出 SSL 相关错误以加载网站

C# Selenium ChromeDriverService throwing SSL related error on windows 11 OS for loading web site

提问人:Sankar 提问时间:9/26/2023 最后编辑:TylerHSankar 更新时间:9/29/2023 访问量:47

问:

我有一个小的 c# 控制台程序,它使用 Selenium 逐个加载 URL 列表并解析一些文本数据。我们的程序在 Windows 10 操作系统上成功运行,但在 Windows 11 操作系统上运行我的程序时,收到以下错误消息:

see my error message screen shot

从错误图像来看,错误似乎与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();
  1. 为了克服这个问题,我以这种方式使用了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 的设置中设置或更改什么?

C# 硒网络驱动程序 SSL SSL 证书 Windows-11

评论

0赞 jdweng 9/26/2023
阅读错误消息。消息显示连接已完成,因此不是 TLS 问题。登录过程中出现错误失败。该错误是由身份验证或凭据引起的。是多种类型的凭据。您可能使用的是 Windows(基本)或 OAUTH2。请参见 : stackoverflow.com/questions/65689725/...
0赞 Sankar 9/26/2023
这样应用程序登录到站点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
0赞 jdweng 9/26/2023
在代码上放置断点,看看它在哪里失败。TLS 在发送 http 请求之前执行。由于 Net 4.7.1 默认情况下,TLS 是在操作系统中执行的,而不是在 Net 中执行的,除非您指定了 Net/Core。您添加的代码可能会使问题变得更糟,而不是凭据失败,而是在TLS上早期失败。删除服务点代码并解决实际问题。Win 11 可能不接受未加密的密码,您需要使用凭据(或默认凭据)加密密码。

答: 暂无答案