Selenium 和 Python 中的 ElementClickInterceptedException 解决方案

穆拉特塔西

我将在网站上按自动化按钮,但与此同时,名为活动(kampanyalar)的东西正在阻止它。我该如何解决这个问题?我希望其他元素不要获得 click 属性

错误:

ElementClickInterceptedException: element click intercepted: Element <div class="styled__CampaignCardDescriptionTitle-sc-1n4y3hk-2 hulWUi" color="">...</div> is not clickable at point (531, 35). Other element would receive the click: <a class="styled__HeaderMenuItem-sc-126ws66-35 gEoUee" href="/kampanyalar" id="DPE_TR_HOME_BUTTON_HEADERITEM0">...</a>
预言家

ElementClickInterceptedException可能由多种原因引起。
最强大的是用JavaScript点击而不是webdriver点击。像下面这样:

element = driver.find_element_by_xpath("xpath")
driver.execute_script("arguments[0].click();", element)

但是最好看看是什么导致了这个异常。
如果元素不在可见屏幕或某些页脚元素与其重叠,最好将该元素滚动到视图中:

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_xpath("xpath")
driver.execute_script("arguments[0].scrollIntoView();", element)

在其他一些情况下,会发生这种情况是因为您在页面仍在加载元素时尝试单击该元素,因此当前在该元素上找到了其他一些元素。在这种情况下,最好等待该元素变得可点击。像这样:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "xpath"))).click()

因此,最好根据您在那里面临的具体情况使用更多与用户相似的操作,并且只有在没有替代方法可以使用 JavaScript 点击的情况下

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用sendkey在textarea中输入python代码,但不起作用。有什么解决方案吗?(Selenium Java)

如何在Python中从文件读取和删除前n行-优雅的解决方案

在python 2和python 3中运行代码时的不同解决方案

如何用多个解决方案来解决多项式,包括python中的复杂解决方案?

MATLAB和Python中线性编程中的冲突解决方案

Python中的Excel Solver解决方案。西皮不工作

ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素<label>

selenium.common.exceptions.ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素

Python列表中的交替方向-更多Pythonic解决方案

node.js和python中相同问题解决方案的不同结果

Excel中的多个条件和多个解决方案

Selenium无法单击ElementClickInterceptedException Selenium按钮Python

Python在O(1)解决方案中引发算术错误

从Python列表中删除重复项的更好解决方案

清除python列表推导中缺少值的解决方案

Python中的N皇后回溯:如何返回解决方案而不是打印解决方案?

Python全局变量和WCF解决方案指南

在optaplanner中获得更少的解决方案和更多的机会

CRM动态中的默认解决方案导入和导出解决方案。

python中的方程式解决方案集

Python 3中的密码算术类通用解决方案

Mac OS X中的视频和字幕解决方案

如何在 Python 中读取和删除文件中的前 n 行 - 优雅的解决方案 [2]

Python 中的斐波那契 - 简单的解决方案

两个和python解决方案

在 python 中从 Wolfram alpha 获取解决方案

二进制搜索在 Python 中的解决方案

Pandas 中 groupby 和聚合的更快解决方案

Python selenium 中的 ElementClickInterceptedException