如何解决:This version of Microsoft Edge WebDriver only supports Microsoft Edge version 129(驱动版本不匹配)

Traceback (most recent call last): File "d:\Workplace\Python\test2.py", line 19, in <module> driver = webdriver.Edge(service=service, options=edge_options) File "D:\python\Lib\site-packages\selenium\webdriver\edge\webdriver.py", line 45, in __init__ super().__init__( ~~~~~~~~~~~~~~~~^ browser_name=DesiredCapabilities.EDGE["browserName"], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... keep_alive=keep_alive, ^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "D:\python\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 67, in __init__ super().__init__(command_executor=executor, options=options) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 260, in __init__ self.start_session(capabilities) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 448, in execute self.error_handler.check_response(response) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "D:\python\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir Stacktrace: GetHandleVerifier [0x00007FF7EC96FCA5+25029] (No symbol) [0x00007FF7EC8C4CB0] Microsoft::Applications::Events::EventProperty::to_string [0x00007FF7ECBCADAA+1947706] (No symbol) [0x00007FF7EC6C280D] (No symbol) [0x00007FF7EC6C03B3] (No symbol) [0x00007FF7EC7052CD] (No symbol) [0x00007FF7EC7043CB] (No symbol) [0x00007FF7EC6F8DF3] (No symbol) [0x00007FF7EC6CD6A6] (No symbol) [0x00007FF7EC6CCBB3] (No symbol) [0x00007FF7EC6CD4D3] (No symbol) [0x00007FF7EC7D5D0D] (No symbol) [0x00007FF7EC7E38AF] (No symbol) [0x00007FF7EC7DC29F] Microsoft::Applications::Events::EventProperty::to_string [0x00007FF7ECA34D5A+284650] (No symbol) [0x00007FF7EC8D2641] (No symbol) [0x00007FF7EC8CB0E4] (No symbol) [0x00007FF7EC8CB233] (No symbol) [0x00007FF7EC8BCE76] BaseThreadInitThunk [0x00007FFF5E02E8D7+23] RtlUserThreadStart [0x00007FFF5E61C5DC+44]
最新发布
05-17
### 解决 Selenium Edge 浏览器启动时出现的 `SessionNotCreatedException` 错误 当尝试通过 Selenium 启动 Microsoft Edge 浏览器时,如果遇到错误 `selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of MSEdgeDriver only supports MSEdge version 102`, 这通常是因为浏览器驱动程序 (MSEdgeDriver) 和实际安装的 Edge 浏览器版本匹配所致[^1]。 以下是可能导致此问题的原因以及解决方案: #### 原因分析 1. **Edge 驱动版本与浏览器版本符**: 如果使用的 MSEdgeDriver 版本支持特定范围内的 Edge 浏览器版本,而当前机器上的 Edge 浏览器已更新到更高版本,则会触发该异常。 2. **用户数据目录冲突**: 当多个实例试图访问同一个用户配置文件 (`User Data Directory`) 或者未正确关闭之前的浏览器进程时,也可能引发类似的错误消息。 3. **权限足或其他环境因素**: 文件系统的读写权限受限或者某些杀毒软件阻止了对临时文件夹的操作也可能是原因之一。 #### 解决方案 为了有效处理这个问题可以从以下几个方面入手: 1. **确认并下载对应版本的 MSEdgeDriver** - 访问官方站点 https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 查看最新发布的兼容性列表,并依据本地计算机所装设之Microsoft Edge的实际版本号来选取相适配的webdriver版本. 2. **设置新的 User Data Directory 参数** 使用命令行参数指定同的用户资料路径可以避免重复使用同一份档案造成干扰。例如,在初始化 WebDriver 实例前加入以下选项: ```python from selenium import webdriver from selenium.webdriver.edge.service import Service options = webdriver.EdgeOptions() options.add_argument("--user-data-dir=C:\\Path\\To\\Custom\\Profile") # 设置自定义用户数据目录 service = Service(executable_path="path/to/msedgedriver.exe") driver = webdriver.Edge(service=service, options=options) ``` 3. **清理残留进程** 确保先前执行过程中遗留下来的任何旧版edge窗口已被完全终止掉再重新开启新测试流程;可以通过任务管理器手动结束所有相关联的服务项或是利用脚本来实现自动化清除功能。 4. **升级至最新稳定发行版** 定期检查是否有可用的新版本发布可供下载应用从而保持工具链始终处于良好状态之下减少必要的麻烦发生几率. --- ```python from selenium import webdriver from selenium.webdriver.edge.service import Service # Define path variables accordingly on your system setup ms_edge_driver_path = r"C:\WebDrivers\msedgedriver.exe" custom_user_data_dir = r"C:\Temp\SeleniumProfiles" options = webdriver.EdgeOptions() options.add_argument(f"--user-data-dir={custom_user_data_dir}") service = Service(ms_edge_driver_path) try: driver = webdriver.Edge(service=service, options=options) finally: if 'driver' in locals(): driver.quit() # Ensure proper cleanup after execution completes or fails unexpectedly ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-O-joker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值