selenium的异常:ElementClickInterceptedException

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

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button data-v-3916f4c2="" type="button" class="el-button el-button--primary" style="width: 100%; height: 50px; border-radius: 10px; margin-top: 20px;">...</button> is not clickable at point (688, 398). Other element would receive the click: <div data-v-3916f4c2="" class="login-top">...</div>

解决方案一:强制等待多等待几秒钟

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

解决方案二:通过selenium调用js直接操作

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

 

显示等待:
这里使用的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 ec

try:
element = WebDriverWait(driver, 5).until(ec.visibility_of_element_located(loc))
except TimeoutException:
element.click()

参考资料:https://www.jianshu.com/p/329e231a6bbf

https://blog.csdn.net/weixin_45552310/article/details/111171110

posted @ 2021-11-29 19:04  娜乌西卡在路上  阅读(1333)  评论(0)    收藏  举报