Chrome WebDriver 106出现uniqueContextId未找到异常求助
升级Chrome及WebDriver至106版本后出现
uniqueContextId not found异常 问题描述
近期将Chrome及其WebDriver从103版本升级至106版本后,原本正常运行的代码开始抛出异常,错误信息如下:
OpenQA.Selenium.WebDriverException: invalid argument: uniqueContextId not found (Session info: chrome=106.0.5249.62)
异常抛出位置为:ExpectedConditions.ElementExists(loadingLocator)
解决方案建议
- 严格匹配Chrome与ChromeDriver版本:Chrome 106对应的官方ChromeDriver版本是106.0.5249.61,务必下载该版本替换当前WebDriver,小版本不匹配极易引发兼容性问题。
- 升级Selenium库:将Selenium.WebDriver包更新至4.5.0及以上稳定版,旧版Selenium对Chrome 106的支持存在已知缺陷,新版本已修复相关问题。
- 替换过时的
ExpectedConditions:Selenium 4.x中ExpectedConditions已被标记为弃用,推荐使用WebDriverWait结合Lambda表达式替代,示例代码:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(d => d.FindElement(loadingLocator) != null);
- 排查Chrome启动参数:若代码中配置了自定义启动参数,尝试移除可能导致上下文冲突的参数(如
--disable-site-isolation-trials)后重新测试。
内容的提问来源于stack exchange,提问作者Frank
相关产品推荐
相关产品推荐

