测试人社区

Chrome与chromedriver的匹配问题

一、配置chrome浏览器的驱动chromedriver完毕,
在pycharm验证两者是否匹配,
import selenium
from selenium import webdriver
def test_selenium():
driver = webdriver.Chrome()
driver.get(“https://www.baidu.com/”)
二、运行结果
Testing started at 12:36 …
D:\testingproject\venv\Scripts\python.exe “E:\PyCharm 2020.2\plugins\python\helpers\pycharm_jb_pytest_runner.py” --target test_selenium.py::test_selenium
Launching pytest with arguments test_selenium.py::test_selenium in D:\testingproject\testing

============================= test session starts =============================
platform win32 – Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 – D:\testingproject\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\testingproject\testing
collecting … collected 1 item

test_selenium.py::test_selenium FAILED [100%]
test_selenium.py:8 (test_selenium)
def test_selenium():

  driver = webdriver.Chrome()

test_selenium.py:10:


…\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py:76: in init
RemoteWebDriver.init(
…\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:157: in init
self.start_session(capabilities, browser_profile)
…\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:252: in start_session
response = self.execute(Command.NEW_SESSION, parameters)
…\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
self.error_handler.check_response(response)


self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x04803BC8>
response = {‘sessionId’: ‘45be11902450ef3e2c62cf468b2527bb’, ‘status’: 33, ‘value’: {‘message’: ‘session not created: Chrome vers…ver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.19041 x86_64)’}}

def check_response(self, response):
    """
    Checks that a JSON response from the WebDriver does not have an error.

    :Args:
     - response - The JSON response from the WebDriver server as a dictionary
       object.

    :Ra

三、根据这段运行结果提示:session无法创建:Chrome版本,猜测可能是两者版本不匹配,当前版本为72.0.3626.119
response = {‘sessionId’: ‘45be11902450ef3e2c62cf468b2527bb’, ‘status’: 33, ‘value’: {‘message’: 'session not created: Chrome vers…ver info: chromedriver=2.46.628402
四、下载chrome 72.0.3626.81版本,安装后,再次运行验证通过
五、结论:虽然同为72版本,但对应chromedriver却不一定全部支持,需要试错验证。

镜像源的驱动目录下有notes.txt文件,里面有标注对应的chrome版本。在下载前可查看一下浏览器版本和驱动是否匹配

1 Like