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

相关推荐
MYians2 天前
[Windows]Postman-app官方历史版本下载方法
测试工具·postman
巴里巴气2 天前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
2501_924064112 天前
2025年跨端云真机测试平台深度测评:XR与折叠屏时代的兼容性之战
测试工具·移动端自动化测试·自动化测试脚本
Small black human3 天前
HTTP-Postman的安装及其使用
测试工具·postman
AIZHINAN3 天前
Appium 简介
自动化测试·测试工具·appium
吴free3 天前
mac电脑wireshark快速实现http接口抓包
网络·测试工具·http·wireshark
DeamoTech3 天前
ESCADA
物联网·测试工具
旷世奇才李先生4 天前
Selenium 安装使用教程
selenium·测试工具
巴里巴气4 天前
对selenium进行浏览器和驱动进行配置Windows | Linux
selenium·测试工具
q567315235 天前
Java Selenium反爬虫技术方案
java·爬虫·selenium