Traceback (most recent call last)?​​TOC​

#selenium.common.exceptions.InvalidArgumentException: Message: Expected [object Undefined] undefined

python+selenium 运行报错,定位元素的方法都正确,但就是找不到元素,

Traceback (most recent call last) 无法定位到元素python+selenium_python安装

下面是解决办法

查看项目配置

Traceback (most recent call last) 无法定位到元素python+selenium_python_02

这里提示selenium可以升级

打开dos窗口

先找到python的安装路径

Traceback (most recent call last) 无法定位到元素python+selenium_python安装_03

进入到python安装路径

Traceback (most recent call last) 无法定位到元素python+selenium_python安装_04

查看目前安装的工具 pip list

Traceback (most recent call last) 无法定位到元素python+selenium_python_05

发现selenium不是最新版,把它卸载掉pip uninstall selenium

Traceback (most recent call last) 无法定位到元素python+selenium_python安装_06

Traceback (most recent call last) 无法定位到元素python+selenium_python安装_07

再查看,已经卸载成功

Traceback (most recent call last) 无法定位到元素python+selenium_python_08

安装指定版本的selenium

pip install selenium==4.0.0a1Traceback (most recent call last) 无法定位到元素python+selenium_python安装_09

查看已经安装成功

Traceback (most recent call last) 无法定位到元素python+selenium_python_10

Traceback (most recent call last) 无法定位到元素python+selenium_python_11现在再运行脚本,就没有问题了。