使用selenium时出现element click intercepted报错的解决办法

win10,python3.8.10。

selenium版本如下(用pip38 show selenium查看):

在定位中,定位了一个按钮(特点:button下还有span然后才是文本),代码如下:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

confirm_button=WebDriverWait(xxx_driver, 5).until(
    EC.element_to_be_clickable((By.XPATH,'//button/span[contains(text(), "确定")]'))
)

定位是没有问题的。然后执行如下点击代码:

confirm_button.click()

就会报错了:element click intercepted: Element <span>...</span> is not clickable。

解决办法:

将点击代码改为如下即可:

webdriver.ActionChains(xxx_driver).move_to_element(confirm_button).click(confirm_button).perform()

可以参考我的文章: selenium中出现 Other element would receive the click的解决方式-CSDN博客

也可以参考文章:

element click intercepted: Element <span>...</span> is not clickable报错解决办法_element click intercepted: element <span>...</span-CSDN博客

或者:

https://www.cnblogs.com/soundcode/p/15910729.html

对于这篇文章,我测试第一种方法并不好用,第二种好用。

相关推荐
刀客1236 分钟前
python小项目编程-中级(1、图像处理)
开发语言·图像处理·python
信阳农夫19 分钟前
python 3.6.8支持的Django版本是多少?
python·django·sqlite
一个幽默的程序员29 分钟前
API测试工具:Swagger vs Postman 2025最新全面对比
测试工具·postman
冷琴199630 分钟前
基于Python+Vue开发的反诈视频宣传管理系统源代码
开发语言·vue.js·python
带娃的IT创业者40 分钟前
《Python实战进阶》专栏 No2: Flask 中间件与请求钩子的应用
python·中间件·flask
坚持就完事了1 小时前
Python之numpy
开发语言·python·numpy
jxf_jxfcsdn1 小时前
python读取pdf文档
开发语言·python·pdf
摆烂老大2 小时前
SWAT| 水文 | SWAT模型(四):气象数据库制备(附Python代码)
python·arcgis·水文·swat模型
晓星航2 小时前
8.python文件
python·文件·文件操作·基础语法
程序员JerrySUN2 小时前
每天设计者模式-1:基础面试题
java·linux·运维·服务器·开发语言·python·docker