ChromeDriver与Chrome版本不匹配导致会话创建失败问题求助
解决ChromeDriver版本不匹配导致的SessionNotCreatedException问题
定位并删除旧版ChromeDriver
打开命令提示符(cmd),执行命令:where chromedriver,该命令会列出系统中所有可被调用的ChromeDriver路径。找到对应版本114.0.5735.90的文件,直接删除。显式指定ChromeDriver与Chrome路径
在Java代码中明确指定新版ChromeDriver和Chrome浏览器的路径,避免系统自动选择旧版本。示例代码:System.setProperty("webdriver.chrome.driver", "C:\\path-to-your-chromedriver-116\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); WebDriver driver = new ChromeDriver(options);若使用Selenium 4.6及以上版本,可利用内置的DriverManager自动管理版本,无需手动下载配置,示例代码:
ChromeOptions options = new ChromeOptions(); options.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); WebDriver driver = new ChromeDriver(options);调整环境变量PATH优先级
进入系统环境变量设置,在系统变量的PATH中,将新版ChromeDriver所在路径移至顶部,确保系统优先调用该版本;若PATH中存在旧版ChromeDriver的路径,直接移除。验证版本一致性
进入新版ChromeDriver目录,执行chromedriver --version,确认输出版本为116.0.5845.96;同时在Chrome浏览器地址栏输入chrome://version/,确认浏览器版本为116.0.5845.97,主版本号匹配即可。
内容的提问来源于stack exchange,提问作者Hrushikesh Shewale
相关产品推荐
相关产品推荐

