selenium.common.exceptions.ElementClickInterceptedException报错问题

selenium新手上路问题记录

// 定位某个元素,并点击
driver.find_element_by_css_selector('xxxxx’).click()
# 报错:
selenium.common.exceptions.ElementClickInterceptedException

意思是点不到呗,没有定位到元素所以没有办法点击,一般两个情况:

一、未加载完成。

解决办法:


# 加载驱动
driver = webdriver.Chrome(r'xxxxxx')		
# 设置隐式等待时间
driver.implicitly_wait(5)
		

二、元素被遮挡:

a:向下滚动进度条,定位到元素出现的位置

a = driver.find_element_by_css_selector('xxxxx’)
# 让页面直接跳到元素出现的位置
driver.execute_script("arguments[0].scrollIntoView()", a)
a.click()

b.向上滚动进度条,定位到元素出现的位置

a = driver.find_element_by_css_selector('xxxxx’)
# 让页面直接跳到元素出现的位置
driver.execute_script("arguments[0].scrollIntoView(false)", a)
a.click()

成功解决~~~~

你可能感兴趣的:(selenium)