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()
这篇关于您如何修复“元素不可交互"?例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您如何修复“元素不可交互"?例外?
基础教程推荐
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
