异常: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
发布评论