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

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

相关推荐
淡忘旧梦15 分钟前
词错误率/WER算法讲解
人工智能·笔记·python·深度学习·算法
癫狂的兔子17 分钟前
【Python】【爬虫】爬取虎扑网NBA排行数据
数据库·爬虫·python
Aurora-Borealis.24 分钟前
Day40 早停策略和模型权重的保存
python
好大哥呀25 分钟前
如何在手机上运行Python程序
开发语言·python·智能手机
_codemonster26 分钟前
手语识别及翻译项目实战系列(一)环境准备
人工智能·python·计算机视觉
毕设源码-钟学长27 分钟前
【开题答辩全过程】以 基于Python的新闻热点舆情分析系统为例,包含答辩的问题和答案
开发语言·python
2401_8414956428 分钟前
【Python高级编程】单词统计与查找分析工具
数据结构·python·算法·gui·排序·单词统计·查找
XerCis28 分钟前
Python代码检查与格式化工具Ruff
开发语言·python
西红市杰出青年35 分钟前
asyncio.gather 内部原理与运行机制(详解)
网络·python·异步
70asunflower37 分钟前
torch.manual_seed()介绍
人工智能·pytorch·python