You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用WebDriverManager安装ChromeDriver时触发AttributeError问题

解决Windows下Selenium+webdriver_manager触发AttributeError的问题

报错核心

执行常规Selenium4代码安装Chrome驱动时,触发AttributeError: 'NoneType' object has no attribute 'split',根源是webdriver_manager未能成功检测到本地Chrome浏览器的版本号,导致后续对None对象调用split方法失败。

解决方案

1. 确认Chrome浏览器安装状态

  • 检查Chrome是否已正确安装,默认路径为C:\Program Files\Google\Chrome\Application\chrome.exe
  • 将Chrome安装路径添加到系统环境变量PATH中,确保能通过命令行直接调用chrome
  • 若Chrome安装在非默认路径,可在代码中指定Chrome二进制文件路径:
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService
    from webdriver_manager.chrome import ChromeDriverManager
    
    options = webdriver.ChromeOptions()
    options.binary_location = r"C:\Your\Custom\Path\To\chrome.exe"
    driver = webdriver.Chrome(options=options, service=ChromeService(ChromeDriverManager().install()))
    

2. 升级webdriver_manager到最新版本

旧版本可能存在浏览器版本检测的bug,执行以下命令升级:

pip install --upgrade webdriver-manager

3. 手动指定ChromeDriver版本绕过自动检测

如果已知本地Chrome的版本号(通过Chrome设置→关于Chrome查看),直接在ChromeDriverManager中指定版本:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

# 替换为你的Chrome实际版本号,例如125.0.6422.112
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(version="125.0.6422.112").install()))

4. 以管理员权限运行脚本

Windows下webdriver_manager通过读取注册表获取Chrome信息,权限不足可能导致读取失败,右键点击Python脚本或终端选择「以管理员身份运行」。

内容的提问来源于stack exchange,提问作者Togrul Kazimov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 18:54:51