selenium的异常:selenium.common.exceptions.ElementClickInterceptedException: Message: element click inte

编程入门 行业动态 更新时间:2024-10-22 22:53:04

selenium的<a href=https://www.elefans.com/category/jswz/34/1771210.html style=异常:selenium.common.exceptions.ElementClickInterceptedException: Message: element click inte"/>

selenium的异常:selenium.common.exceptions.ElementClickInterceptedException: Message: element click inte

报错信息如下:大致意思就是当前元素是不可以点击,但是确实存在在页面上,有可能是被loading覆盖了

seleniummon.exceptions.ElementClickInterceptedException: Message: element click intercepted:

解决思路:

1.强制等待,多等待几秒能解决问题,但是不灵活

# 可以强制等待
import time
time.sleep()

2.通过selenium调用JS直接操作

js = driver.find_element(By.CSS_SELECTOR, 'xxx')
driver.execute_script("arguments[0].click();", js)

3.显示等待:

里使用的visibility_of_element_located,区别于presence_of_element_located
visibility_of_element_located:找到元素后元素的宽高必须大于0才执行;
presence_of_element_located:找到元素后直接执行,也许元素被蒙层遮住,或者loading遮住会造成无法点击

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ectry:element = WebDriverWait(driver, 5).until(ec.visibility_of_element_located(loc))
except TimeoutException:element.click()



 

更多推荐

selenium的异常:selenium.common.exceptions.ElementClickInterceptedException: Message

本文发布于:2024-03-05 05:08:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1711385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   exceptions   common   selenium   ElementClickInterceptedException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!