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)
相关推荐
Lossya4 小时前
【自动化测试】UI自动化的分类、如何选择合适的自动化测试工具以及其中appium的设计理念、引擎和引擎如何工作
自动化测试·测试工具·ui·appium·自动化
waterHBO14 小时前
python 爬虫 selenium 笔记
爬虫·python·selenium
chenjingming6661 天前
windows使用tcpdump.exe工具进行抓包教程
网络·测试工具·tcpdump
小码哥说测试1 天前
软件测试技术之 GPU 单元测试是什么!
自动化测试·功能测试·测试工具·jmeter·单元测试·集成测试·postman
全能全知者2 天前
不废话简单易懂的Selenium 页面操作与切换
python·selenium·测试工具·网络爬虫
测试19982 天前
使用Selenium进行网页自动化
自动化测试·软件测试·python·selenium·测试工具·自动化·测试用例
做一道光2 天前
1、QAC静态测试常用操作
软件测试·测试工具·静态测试
假女吖☌2 天前
postman接口关联
测试工具·postman
测试杂货铺2 天前
selenium元素定位:元素点击交互异常解决方法
自动化测试·软件测试·python·selenium·测试工具·职场和发展·单元测试
讓丄帝愛伱3 天前
PostMan使用变量
测试工具·postman