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

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

相关推荐
AI蜗牛之家3 小时前
Qwen系列之Qwen3解读:最强开源模型的细节拆解
人工智能·python
whyeekkk4 小时前
python打卡第48天
开发语言·python
Eiceblue6 小时前
Python读取PDF:文本、图片与文档属性
数据库·python·pdf
weixin_527550406 小时前
初级程序员入门指南
javascript·python·算法
程序员的世界你不懂7 小时前
Appium+python自动化(十)- 元素定位
python·appium·自动化
CryptoPP7 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
树叶@7 小时前
Python数据分析7
开发语言·python
老胖闲聊8 小时前
Python Rio 【图像处理】库简介
开发语言·图像处理·python
码界奇点9 小时前
Python Flask文件处理与异常处理实战指南
开发语言·python·自然语言处理·flask·python3.11
浠寒AI9 小时前
智能体模式篇(上)- 深入 ReAct:LangGraph构建能自主思考与行动的 AI
人工智能·python