报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法

报错 AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ 解决方法

汉: AttributeError:“WebDriver”对象没有属性“find_elements_by_xpath”


快捷操作:可选择文章目录来快速直达查看

文章目录

  • 报错 AttributeError: 'WebDriver' object has no attribute 'find_elements_by_xpath' 解决方法
  • 前言
  • 一、解决方法1
  • 二、解决方法2


前言

  • 为什么会报这个错误提示呢?
    报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法_第1张图片

问题解析:使用Selenium库版本语法输写格式不同引起的问题

查看库终端命令:pip show Selenium
当前库版本:
报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法_第2张图片


提示:以下是本篇文章正文内容,下面案例可供参考

一、解决方法1

  • 直接修改旧代码为新库代码语法输写格式

旧代码如下(示例):

img = driver.find_elements_by_xpath("//*[@id='srcPic']")

新库代码如下(示例):

wd.find_element(By.XPATH, "//*[@id='srcPic']")

二、解决方法2

  1. 卸载selenium新库,安装回旧库

终端命令:pip3 uninstall selenium
报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法_第3张图片

  • 安装指定selenium库
    终端命令:pip3 install selenium==4.4.2
    报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法_第4张图片

  • 或直接使用国内镜像安装库
    终端命令:
    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -U selenuim==4.4.2

    报错 AttributeError: ‘WebDriver‘ object has no attribute ‘find_elements_by_xpath‘ 解决方法_第5张图片

你可能感兴趣的:(python,开发语言)