selenium报错:element not interact

文章目录

报错分析

报错:

python 复制代码
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

ElementNotInteractableException异常表示无法与元素交互,通常是由于该元素不可见、被其他元素遮挡或者需要滚动页面才能被显示。

解决办法

以下是一些可能导致该异常出现的情况和解决办法:

  1. 元素被遮挡:该元素可能被其他元素遮挡,或者被当前浏览器窗口以外的元素遮挡。可以尝试使用execute_script()方法将页面滚动到该元素可见的位置,或者使用ActionChains类模拟鼠标操作移动到该元素上方。

  2. 元素未加载完成:该元素可能还未加载完成就被尝试交互了。可以使用WebDriverWait类等待元素加载出来后再进行交互操作,例如:

python 复制代码
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

# 等待元素加载出来
element = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, "xpath of element"))
)

# 点击元素
element.click()
  1. 元素被设为不可交互:该元素可能被设置为不可交互(例如disabled属性)。在这种情况下,需要检查该元素属性是否正确,或者尝试使用JavaScript代码删除该属性,例如:
python 复制代码
element = driver.find_element_by_xpath("xpath of element")
driver.execute_script("arguments[0].removeAttribute('disabled')", element)
相关推荐
惜.己1 小时前
使用python读取json数据,简单的处理成元组数组
开发语言·python·测试工具·json
baynk12 小时前
wireshark的常用用法
网络·测试工具·wireshark·ctf
维度软件库13 小时前
集中打印和转换Office 批量打印精灵:Word/Excel/PDF 全兼容,效率翻倍
测试工具·电脑·开源软件
测试老哥2 天前
Jmeter+ant+jenkins接口自动化测试框架
自动化测试·软件测试·python·测试工具·jmeter·jenkins·压力测试
技术猿188702783512 天前
实现“micro 关键字搜索全覆盖商品”并通过 API 接口提供实时数据(一个方法)
开发语言·网络·python·深度学习·测试工具
格鸰爱童话3 天前
python+selenium UI自动化初探
python·selenium·自动化
autobaba3 天前
编写bat文件自动打开chrome浏览器,并通过selenium抓取浏览器操作chrome
chrome·python·selenium·rpa
计算机毕设定制辅导-无忧学长4 天前
Modbus 开发工具实战:ModScan32 与 Wireshark 抓包分析(一
网络·测试工具·wireshark
有谁看见我的剑了?4 天前
iperf3 网络带宽测试工具学习
学习·测试工具
q567315234 天前
Selenium动态网页爬虫编写与解释
爬虫·selenium·测试工具