使用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

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

相关推荐
蹦蹦跳跳真可爱5893 小时前
Python----OpenCV(图像増强——高通滤波(索贝尔算子、沙尔算子、拉普拉斯算子),图像浮雕与特效处理)
人工智能·python·opencv·计算机视觉
nananaij3 小时前
【Python进阶篇 面向对象程序设计(3) 继承】
开发语言·python·神经网络·pycharm
雷羿 LexChien3 小时前
从 Prompt 管理到人格稳定:探索 Cursor AI 编辑器如何赋能 Prompt 工程与人格风格设计(上)
人工智能·python·llm·编辑器·prompt
敲键盘的小夜猫3 小时前
LLM复杂记忆存储-多会话隔离案例实战
人工智能·python·langchain
高压锅_12204 小时前
Django Channels WebSocket实时通信实战:从聊天功能到消息推送
python·websocket·django
胖达不服输5 小时前
「日拱一码」020 机器学习——数据处理
人工智能·python·机器学习·数据处理
吴佳浩5 小时前
Python入门指南-番外-LLM-Fingerprint(大语言模型指纹):从技术视角看AI开源生态的边界与挑战
python·llm·mcp
吴佳浩6 小时前
Python入门指南-AI模型相似性检测方法:技术原理与实现
人工智能·python·llm
叶 落6 小时前
计算阶梯电费
python·python 基础·python 入门
Python大数据分析@7 小时前
Origin、MATLAB、Python 用于科研作图,哪个最好?
开发语言·python·matlab