目录
背景:
?错误代码:
报错分析:
?正确代码:
参考链接:
背景:
点击课堂派官网,点击登录按钮,想进入登录页面
?课堂派官网地址:https://prepc.ketangpai.com/#/homePage
?错误代码:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
url="https://prepc.ketangpai.com/#/homePage"
driver = webdriver.Chrome()
driver.maximize_window()
time.sleep(1)
driver.get(url)
# 点击登录按钮
driver.find_element(By.XPATH,'//button[@class="el-button el-button--default el-button--medium"]').click()
time.sleep(5)
driver.quit()
报错分析:
selenium.common.exceptions.ElementClickInterceptedException:
Message: element click intercepted: Element is not clickable at point
Other element would receive the click
重点信息:
selenium.common.exceptions.ElementClickInterceptedException:
Element is not clickable Other element would receive the click
元素点击被拦截异常
该元素不能被点击,本地点击将会被转移到其他元素上
?正确代码:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
url="https://prepc.ketangpai.com/#/homePage"
driver = webdriver.Chrome()
driver.maximize_window()
time.sleep(1)
driver.get(url)
# 点击登录按钮
element = driver.find_element(By.XPATH, '//button[@class="el-button el-button--default el-button--medium"]')
driver.execute_script("arguments[0].click();",element )
time.sleep(5)
driver.quit()
通过执行js代码来点击登录按钮
参考链接:
scrapy解决selenium中无法点击Element:ElementClickInterceptedException_学习真的很有用的博客-CSDN博客
Python selenium报错:selenium.common.exceptions.ElementClickInterceptedException_xupeng1644的博客-CSDN博客
|