解决:selenium web browser 的版本适配问题

文章目录

  • [解决方案:使用 webdriver manager 自动适配驱动](#解决方案:使用 webdriver manager 自动适配驱动)

  • 使用 selenium 操控浏览器的时候报错:

    The chromedriver version (114.0.5735.90) detected in PATH at /opt/homebrew/bin/chromedriver might not be compatible with the detected chrome version (122.0.6261.69); currently, chromedriver 122.0.6261.69 is recommended for chrome 122.*, so it is advised to delete the driver in PATH and retry
    Traceback (most recent call last):
    File "/Users/qinpeinuan/Desktop/NUS/2024 sem1/CS5342 Multi-media computing/recommendation_system/perception_evaluation/TemplateFill.py", line 11, in <module>
    driver = webdriver.Chrome()
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init
    super().init(
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 61, in init
    super().init(command_executor=executor, options=options)
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in init
    self.start_session(capabilities)
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
    File "/Users/qinpeinuan/opt/anaconda3/envs/rs/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
    Current browser version is 122.0.6261.69 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    Stacktrace:
    0 chromedriver 0x0000000102e5bf48 chromedriver + 4226888
    1 chromedriver 0x0000000102e544f4 chromedriver + 4195572
    2 chromedriver 0x0000000102a98d68 chromedriver + 281960
    3 chromedriver 0x0000000102ac4bac chromedriver + 461740
    4 chromedriver 0x0000000102ac0fd8 chromedriver + 446424
    5 chromedriver 0x0000000102abe150 chromedriver + 434512
    6 chromedriver 0x0000000102afb93c chromedriver + 686396
    7 chromedriver 0x0000000102afb164 chromedriver + 684388
    8 chromedriver 0x0000000102ac7f1c chromedriver + 474908
    9 chromedriver 0x0000000102ac8ef4 chromedriver + 478964
    10 chromedriver 0x0000000102e1d59c chromedriver + 3970460
    11 chromedriver 0x0000000102e216f0 chromedriver + 3987184
    12 chromedriver 0x0000000102e275b4 chromedriver + 4011444
    13 chromedriver 0x0000000102e222fc chromedriver + 3990268
    14 chromedriver 0x0000000102dfa1c0 chromedriver + 3826112
    15 chromedriver 0x0000000102e3e088 chromedriver + 4104328
    16 chromedriver 0x0000000102e3e1e0 chromedriver + 4104672
    17 chromedriver 0x0000000102e4df28 chromedriver + 4169512
    18 libsystem_pthread.dylib 0x0000000187e01034 _pthread_start + 136
    19 libsystem_pthread.dylib 0x0000000187dfbe3c thread_start + 8

解决方案:使用 webdriver manager 自动适配驱动

python 复制代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

option = webdriver.ChromeOptions()
option.add_argument("start-maximized")


driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get('https://www.google.com/')
相关推荐
Cachel wood12 分钟前
python round四舍五入和decimal库精确四舍五入
java·linux·前端·数据库·vue.js·python·前端框架
学代码的小前端13 分钟前
0基础学前端-----CSS DAY9
前端·css
joan_8517 分钟前
layui表格templet图片渲染--模板字符串和字符串拼接
前端·javascript·layui
m0_748236111 小时前
Calcite Web 项目常见问题解决方案
开发语言·前端·rust
Watermelo6171 小时前
详解js柯里化原理及用法,探究柯里化在Redux Selector 的场景模拟、构建复杂的数据流管道、优化深度嵌套函数中的精妙应用
开发语言·前端·javascript·算法·数据挖掘·数据分析·ecmascript
m0_748248941 小时前
HTML5系列(11)-- Web 无障碍开发指南
前端·html·html5
m0_748235611 小时前
从零开始学前端之HTML(三)
前端·html
一个处女座的程序猿O(∩_∩)O3 小时前
小型 Vue 项目,该不该用 Pinia 、Vuex呢?
前端·javascript·vue.js
hackeroink6 小时前
【2024版】最新推荐好用的XSS漏洞扫描利用工具_xss扫描工具
前端·xss
迷雾漫步者8 小时前
Flutter组件————FloatingActionButton
前端·flutter·dart