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

使用RobotFramework运行脚本报错:'WebDriver'无'find_elements_by_xpath'属性

解决AttributeError: 'WebDriver' object has no attribute 'find_elements_by_xpath'问题

问题原因

你使用的Selenium Library 4.1.0基于Selenium 4.x开发,而Selenium 4.x已经彻底移除了find_elements_by_xpath这类旧版定位方法,改用find_element()搭配By类的新写法。但你的RobotFramework 3.2.2版本过老,和Selenium Library 4.x存在兼容性冲突,导致底层调用了已被删除的方法,触发报错,所以仅能打开浏览器,无法执行后续操作。

修复方案

  • 降低Selenium Library版本:安装与RobotFramework 3.2.2兼容的3.x系列版本,执行命令:

    pip uninstall robotframework-seleniumlibrary
    pip install robotframework-seleniumlibrary==3.3.1
    
  • 升级RobotFramework版本:将RobotFramework升级至4.0及以上(支持Selenium Library 4.x),执行命令:

    pip uninstall robotframework
    pip install robotframework==4.1.3
    
  • 调整脚本定位语法:如果不想改动版本,确保脚本使用Selenium Library 4.x支持的关键字,示例:

    # 正确写法示例
    Get WebElements    xpath=//div[@class='target']
    Find Element      xpath=//input[@id='username']
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 14:25:00