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

相关推荐
一个幽默的程序员1 小时前
如何快速备份你的 API 吗? Postman 批量导出接口
测试工具·postman
Cc_Davis_cC1 小时前
postman发送请求报文到后台中文乱码
测试工具·postman
一个幽默的程序员1 小时前
Postman 集合如何快速分享给团队?
测试工具·postman
一个幽默的程序员16 小时前
Postman 如何发送 Post 请求上传文件? 全面指南
测试工具·postman
心灵宝贝16 小时前
Postman 7.3.5 旧版下载指南(Win64)及注意事项
测试工具·postman
测试199821 小时前
postman测试文件上传接口详解
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
微臣愚钝21 小时前
【15】Selenium 爬取实战
爬虫·python·selenium
一个幽默的程序员1 天前
Postman 全局 Header 如何设置?全局设置了解一下
测试工具·postman
一个幽默的程序员1 天前
API 请求需要证书认证? 如何在 Postman 中正确配置和使用?
测试工具·postman
梦想画家1 天前
Playwright从入门到实战:比Selenium更快的数据爬取案例实战
selenium·测试工具·playwright