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

Selenium更新后触发AttributeError,回退及重装无效求助

Selenium更新后AttributeError问题的解决方案

问题根源

报错AttributeError: module 'selenium' has no attribute 'webdriver'主要是Selenium版本变更导致API结构变化,加上IPython缓存残留、Windows .NET更新可能干扰了Python依赖加载,即使回退旧版本也没彻底清理干净环境。

具体解决步骤

  • 彻底清理并重装指定Selenium版本

    1. 卸载所有Selenium相关包:
      pip uninstall -y selenium selenium-webdriver
      
    2. 手动删除Python安装目录下Lib\site-packages里的selenium文件夹和selenium-*.dist-info文件夹,确保无残留
    3. 重新安装周一可用的旧版本(比如3.141.0):
      pip install selenium==3.141.0
      
  • 清空IPython缓存

    1. 关闭当前所有IPython会话、Jupyter内核,重启终端/Notebook服务
    2. 执行代码前强制刷新模块:
      import importlib
      import selenium
      importlib.reload(selenium)
      
  • 排查.NET更新的影响

    1. 检查系统PATH变量,确保Python安装路径和Scripts文件夹排在最前面,避免其他程序干扰
    2. 验证Selenium安装路径:
      import selenium
      print(selenium.__file__)
      
      确认输出路径是刚安装的旧版本文件夹,不是其他位置的残留
    3. 若pip缓存有问题,用无缓存参数重装:
      pip install --no-cache-dir selenium==3.141.0
      
  • 调整undetected-chromedriver初始化参数
    Selenium 3.x版本不支持use_subprocess=True参数,尝试去掉该参数:

    driver = uc.Chrome()
    

验证方法

执行以下代码,无报错则说明环境正常:

import selenium
from selenium import webdriver
print(f"Selenium版本: {selenium.__version__}")
# 再测试undetected-chromedriver初始化
import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get("https://www.google.com")

内容的提问来源于stack exchange,提问作者Martin Dinesen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 08:12:45