python selenium 异常:selenium.common.exceptions.ElementClickInterceptedException

异常解读 Message: element click intercepted

异常错误信息为:Message: element click intercepted: Element <button … is not clickable at point (835, 33). Other element would receive the click:


(Session info: chrome=94.0.4606.81)

该错误是在使用 selenium 的时候,元素被其它内容捕获到了,进而可以分析出 BUG 原因,是由于要点击的元素点击不到。

异常解决方案

  • 可以参考下述流程进行分析
    1. 查看是否是待点击元素写错
    2. 查看是否有遮罩层
    3. 查看元素是否被隐藏或移除

具体代码不同,大家自行调整。

如果上述办法都没有解决,可以尝试在 selenium 中执行 JS 代码,进行元素的事件操作。
当然还可以尝试 ActionChains 类与 send_keys() 发送回车键。

附录

本系列文章只供记录 Python 日常开发过程中 偶遇 BUG,提供给学生作为参考数据与解决方案用,属于记录型博客,有缘分看到的读者希望可解决你的问题。

错误提示样板

下述内容,可以与你的错误进行比对。

Traceback (most recent call last):
  File "E:/pythonProject/测试/d5.py", line 21, in <module>
    login_btn.click()
  File "E:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "E:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "E:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "E:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="widget-button btn btn-primary btn-small login-button btn-icon-text">...</button> is not clickable at point (835, 33). Other element would receive the click: <div class="modal-middle-container">...</div>
  (Session info: chrome=94.0.4606.81)

补充一些其他解决方案

selenium.common.exceptions.ElementClickInterceptedException 是 Selenium 中的一个常见异常,通常表示在点击元素时发生了拦截。这意味着在点击元素时,另一个元素挡住了它,导致点击无效。

解决这个问题的方法有以下几种
  • 使用 JavaScript 模拟点击:使用 driver.execute_script() 方法可以执行 JavaScript 代码来点击元素。
  • 等待元素可见:使用 Selenium 的显式等待,等待元素可见后再点击。
  • 滚动到元素位置:使用 driver.execute_script() 方法滚动到元素的位置,这样就可以避免元素被遮挡。
  • 使用 ActionChains: Selenium 提供的 ActionChains 可以模拟鼠标操作,如果点击不了元素,可以使用 move_to_element() 先移动到元素上。
  • 等待元素变化:使用 Selenium 的隐式等待,等待元素发生变化后再点击。

python selenium 异常:selenium.common.exceptions.ElementClickInterceptedException

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦想橡皮擦

如有帮助,来瓶可乐

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值