You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chromedriver从116升级到117后远程运行Selenium测试报错

问题与解决方案

问题描述

在虚拟机环境中,使用Selenium WebDriver 3.141.0配合chromedriver 117.0.5938.88执行自动化测试时出现连接强制关闭错误,切换至chromedriver 116时无此问题,且本地环境运行相同测试完全正常。

错误日志

20-09-2023 15:28:12.756 | ERR | OpenQA.Selenium.WebDriverException: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:51951/session/ed822b3b02fa5ad142a4dd768e5dd8e8/element/3E16DC2127B2C1236A86C156831345F3_element_25969/click. The status of the exception was UnknownError, and the message was: An error occurred while sending the request. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.WebException: An error occurred while sending the request. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.FillAsync()
   at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at System.Net.Http.HttpWebRequest.SendRequest()
   at System.Net.Http.HttpWebRequest.GetResponse()
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)

解决方案

  • 版本兼容性适配:Selenium 3.141.0发布时间较早,对Chrome 117及对应chromedriver的支持存在适配缺陷。建议升级Selenium至4.x版本,新版对高版本ChromeDriver的兼容性更完善。
  • 虚拟机网络排查:检查虚拟机的防火墙、杀毒软件是否拦截了ChromeDriver与WebDriver之间的本地端口连接,可临时关闭防护工具验证问题是否解决。
  • 添加启动参数:初始化ChromeDriver时添加--no-sandbox和--disable-dev-shm-usage参数,规避虚拟机环境下的沙箱限制与内存共享问题。示例代码:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--no-sandbox");
chromeOptions.AddArgument("--disable-dev-shm-usage");
IWebDriver driver = new ChromeDriver(chromeOptions);
  • 版本一致性检查:确认虚拟机中Chrome浏览器版本与chromedriver 117.0.5938.88完全匹配,版本不匹配会导致通信异常。

内容的提问来源于stack exchange,提问作者Dilshan Kay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 19:13:43