selenium.common.exceptions.ElementClickInterceptedException Element is not clickable at point

目录

背景:

 错误代码:

报错分析:

 正确代码:

参考链接:


背景:

点击课堂派官网,点击登录按钮,想进入登录页面

 课堂派官网地址: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博客

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
selenium.common.exceptions.ElementClickInterceptedException是一个常见的异常,表示在尝试点击一个元素时,该元素被其他元素所遮挡或拦截。这通常发生在页面上有多个重叠的元素时。 解决这个异常的方法有以下几种: 1. 使用等待机制:在点击元素之前,使用显式等待来确保元素可见并可点击。可以使用`WebDriverWait`类和`expected_conditions`模块来实现等待机制。 ```python from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By # 等待元素点击 wait = WebDriverWait(driver, 10) element = wait.until(EC.element_to_be_clickable((By.XPATH, "xpath_of_element"))) element.click() ``` 2. 使用JavaScript点击:如果无法通过普通的点击方法点击元素,可以尝试使用JavaScript来模拟点击操作。 ```python element = driver.find_element_by_xpath("xpath_of_element") driver.execute_script("arguments[0].click();", element) ``` 3. 模拟鼠标操作:如果以上方法仍然无法解决问题,可以尝试使用`ActionChains`类来模拟鼠标操作,例如移动到元素上并点击。 ```python from selenium.webdriver.common.action_chains import ActionChains element = driver.find_element_by_xpath("xpath_of_element") actions = ActionChains(driver) actions.move_to_element(element).click().perform() ``` 请注意,以上方法中的`"xpath_of_element"`需要替换为实际元素的XPath表达式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值