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

Selenium Grid搭配Chrome113在MacOS执行测试时抛出加载状态异常

问题描述

我在MacOS 10.15 Catalina系统上,使用Selenium Grid(selenium-server-standalone.3.14.0)搭配chromedriver 113.0.5672.63,基于NUnit运行Selenium测试。部分测试能成功通过,但有部分随机测试在调用IWebElement.Click()时失败,报错信息如下:

unknown error: cannot determine loading status
from unknown error: cannot determine loading status
from no such window
(Session info: chrome=113.0.5672.92).

Exception Stack Trace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary2 parameters)

我怀疑这和Chrome 113的更新有关,类似TestComplete也出现过Chrome 113相关的兼容性问题。

解决办法
  • 升级Selenium版本:Selenium 3.14.0版本过旧,对Chrome 113这类新版本浏览器兼容性不足。建议升级到Selenium 4.x系列(如4.9.0及以上),新版本修复了大量高版本Chrome的兼容问题,可有效避免窗口状态识别错误。
  • 严格匹配Chrome与ChromeDriver版本:当前本地Chrome版本为113.0.5672.92,需下载完全同版本的ChromeDriver替换现有113.0.5672.63版本,版本不匹配会引发会话执行异常。
  • 添加显式等待机制:在点击操作前等待元素可点击且页面加载稳定,避免因页面未就绪导致的错误:
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    IWebElement targetElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("your-element-selector")));
    targetElement.Click();
    
  • 添加Chrome启动参数:尝试添加--disable-features=VizDisplayCompositor参数,可解决Chrome 113中部分渲染相关的会话问题:
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.AddArgument("--disable-features=VizDisplayCompositor");
    IWebDriver driver = new RemoteWebDriver(new Uri("http://your-grid-hub-url:4444/wd/hub"), chromeOptions);
    
  • 检查Selenium Grid环境一致性:确保Grid的Hub和所有节点使用相同版本的Selenium,且每个节点上的Chrome、ChromeDriver版本完全匹配,避免因环境不一致导致的随机失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 10:47:22