selenium 报错 invalid argument: invalid locator

环境:

Python3.12.2 selenium4.0

报错信息:

invalid argument: invalid locator

错误分析:

selenium语法错误,find_element方法少写By.XPATH参数

错误语法如下:

python 复制代码
driver.find_element('//div[@id="myid"]')

解决办法

find_element、find_elements一定要有查找类型参数,例如:By.ID、By.XPATH、By.NAME

python 复制代码
driver.find_element(By.XPATH,'//div[@id="myid"]')

参考资料:

https://blog.csdn.net/m0_47505062/article/details/129041331

相关推荐
我送炭你添花3 小时前
Pelco KBD300A 模拟器:04+1.Python 打包详解:历史、发展与多种方式对比
python·测试工具·运维开发
chuntian_tester5 小时前
Qwen通义千问大模型
测试工具·aigc
少云清6 小时前
【接口测试】3_Postman _Postman断言
测试工具·postman
我一定会有钱7 小时前
pytest基础
python·测试工具·测试用例·pytest
西游音月7 小时前
(6)pytest+Selenium自动化测试-测试用例编写
selenium·测试用例·pytest
Wpa.wk9 小时前
自动化测试 - 文件上传 和 弹窗处理
开发语言·javascript·自动化测试·经验分享·爬虫·python·selenium
少云清9 小时前
【接口测试】4_Postman _全局变量和环境变量
测试工具·postman
卓码软件测评10 小时前
CMA/CNAS软件测评机构:【Gatling数据库性能关联测试JDBC连接和SQL执行时间监控】
数据库·sql·测试工具·性能优化·测试用例
mike041212 小时前
Eclipse+maven+selenium自动化测试用例入门
selenium·eclipse·maven
2501_924064111 天前
2025年接口错误自动分析工具对比与性能测试平台选型指南
测试工具·性能优化·数据可视化