解决selenium.common.exceptions.SessionNotCreatedException:ChromeDriver only supports Chrome version 77

环境

  • Ubuntu 16.04 LTS
  • python 3.x

报错信息:

使用 Chrome 浏览器运行Web自动化测试报错,信息如下:

Traceback (most recent call last):
  File "click_csdn_chromedriver.py", line 80, in 
    click_web(main_page_url)
  File "click_csdn_chromedriver.py", line 13, in click_web
    browser = webdriver.Chrome()
  File "/home/zzh/.local/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/zzh/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/zzh/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/zzh/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/zzh/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, 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 77

原因

chrome和chromedriver版本不匹配


解决方法

  • 1、在chrome浏览器地址里面输入:chrome://version/,查看浏览器版本
    解决selenium.common.exceptions.SessionNotCreatedException:ChromeDriver only supports Chrome version 77_第1张图片

  • 2、找对应的chromedriver版本

    chromedriver下载地址:http://chromedriver.storage.googleapis.com/index.html
    对应我的chrome版本,我下载的是:
    解决selenium.common.exceptions.SessionNotCreatedException:ChromeDriver only supports Chrome version 77_第2张图片

  • 3、 解压
    unzip chromedriver_linux64.zip

  • 4、mv到/usr/local/bin/下

    sudo mv chromedriver /usr/local/bin/

  • 5、查看版本

    chromedriver -v

    ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185})
    
  • 6、再次运行程序,一切ok!


参考

  • http://chromedriver.storage.googleapis.com/index.html
  • Mac Chrome浏览器取消自动升级(填坑版)

你可能感兴趣的:(常见问题)