Selenium自动化测试报错:Chrome failed to start: exited normally求助
问题排查:C# Selenium自动化测试跨.NET版本VM启动报错
本地VM(.NET 6.0.300)上运行正常的C# Selenium自动化测试,在另一台Windows VM(.NET 6.0.407)运行时出现如下报错:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: exited normally. (chrome not reachable)
报错前Chrome浏览器会打开,但标签页标题和地址栏均显示data:,。两台VM代码克隆自同一仓库,启动参数一致,仅.NET版本不同。当前ChromeDriver配置如下(代码中额外添加了--incognito参数):
"chrome": { "webDriverVersion": "Latest", "capabilities": { "enableVNC": true }, "options": { "intl.accept_languages": "en", "safebrowsing.enabled": "true", "profile.default_content_settings.popups": "0", "disable-popup-blocking": "true", "download.prompt_for_download": "false", "download.default_directory": "./downloads" }, "startArguments": [ "--start-maximized", "--no-sandbox", "--disable-popup-blocking", "--disable-gpu", "--disable-dev-shm-usage", "--remote-debugging-port=9222", "--ignore-ssl-errors=yes", "--ignore-certificate-errors" ] },
排查建议
- 校验ChromeDriver与Chrome版本兼容性:尽管配置指定
Latest,但部署时可能未自动同步版本。检查目标VM上ChromeDriver版本是否与Chrome浏览器大版本匹配(例如Chrome 114需对应ChromeDriver 114.x系列),手动下载匹配版本替换后重试。 - 清理重复/冲突启动参数:配置中
--disable-popup-blocking同时出现在options和startArguments中,移除其中一处;--remote-debugging-port=9222若被目标VM其他进程占用,会导致Chrome无法正常启动,更换为9223等未占用端口测试。 - 验证.NET版本影响:在目标VM临时安装.NET 6.0.300,运行测试确认是否正常。若正常则说明是.NET版本升级后的兼容性问题,尝试将Selenium相关NuGet包(如Selenium.WebDriver、Selenium.Support)升级至最新稳定版。
- 检查文件权限:确认测试程序对
./downloads目录有读写权限,或改为绝对路径并确保目录已创建,避免Chrome因无法初始化下载目录退出。 - 移除Windows非必要参数:
--no-sandbox、--disable-dev-shm-usage主要针对Linux环境,在Windows下可移除,简化启动配置后测试。 - 查看Chrome启动日志:添加
--enable-logging --v=1到startArguments,日志会输出到用户目录下的chrome_debug.log,通过日志定位具体退出原因。
内容的提问来源于stack exchange,提问作者AvallaSD
相关产品推荐
相关产品推荐

