美文网首页
selenium的异常:ElementClickIntercep

selenium的异常:ElementClickIntercep

作者: S_jie | 来源:发表于2021-08-05 14:50 被阅读0次

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

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button data-v-9edbb6c6="" type="button" class="el-button course-enter-btn shadow-btn enter-btn-all el-button--default">...</button> is not clickable at point (1185, 292). Other element would receive the click: <div data-v-9edbb6c6="" class="course-desc clearfix">...</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()

相关文章

网友评论

      本文标题:selenium的异常:ElementClickIntercep

      本文链接:https://www.haomeiwen.com/subject/rdmmvltx.html