How do you fix the quot;element not interactablequot; exception?(您如何修复“元素不可交互?例外?)
问题描述
我知道这已经被问过很多次了,但是您如何解决元素不可交互"异常?
I know this has been asked lots of times before but how do you get around the "element not interactable" exception?
我是 Selenium 的新手,如果我有什么问题,请见谅.
I'm new to Selenium so excuse me if I get something wrong.
这是我的代码:
button = driver.find_element_by_class_name(u"infoDismiss")
type(button)
button.click()
driver.implicitly_wait(10)
这是 HTML:
<button class="dismiss infoDismiss">
<string for="inplay_button_dismiss">Dismiss</string>
</button>
这是错误信息:
selenium.common.exceptions.ElementNotInteractableException: Message:
在说消息之后实际上什么都没有.
After is says message there is literally nothing.
我花了很多时间在网上搜索,但没有找到任何可以解决我问题的东西.非常感谢您的回答.
I have spent lots of time searching the web, not finding anything that solves my issue. I would really appreciate an answer.
提前致谢.
将w"更改为驱动程序,以便于阅读
Changed "w" to driver so it is easier to read
更新:我刚刚意识到我找到了错误按钮的 HTML!真正的按钮 HTML 如下:
Update: I have just realized that I've found the HTML of the wrong button! The real button HTML is below:
<button class="dismiss">
<string for="exit">Dismiss</string>
</button>
另外,我使用了答案和评论并编辑了我的代码,如下所示:
Also, I've used the answers and comments and edited my code to look like this:
button = driver.find_element_by_css_selector("button.dismiss")
w.implicitly_wait(10)
ActionChains(w).move_to_element(button).click(button)
现在我得到一个新错误:
And now I get a new error:
selenium.common.exceptions.WebDriverException: Message: Tried to run command without establishing a connection
错误发生在第 1 行:button = driver.find_element_by_css_selector("button.dismiss")
The error happens in line 1: button = driver.find_element_by_css_selector("button.dismiss")
注意:非常感谢所提供的帮助,谢谢
Note: I really appreciate the help that has been given, thanks
推荐答案
有一种可能是该元素当前不可点击,因为它不可见.造成这种情况的原因可能是另一个元素覆盖了它,或者它不在视图中,即它在当前可见区域之外.
A possibility is that the element is currently unclickable because it is not visible. Reasons for this may be that another element is covering it up or it is not in view, i.e. it is outside the currently view-able area.
试试这个
from selenium.webdriver.common.action_chains import ActionChains
button = driver.find_element_by_class_name(u"infoDismiss")
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(button).click(button).perform()
这篇关于您如何修复“元素不可交互"?例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您如何修复“元素不可交互"?例外?
基础教程推荐
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01