问题描述
我知道这已经被问过很多次了,但是您如何解决元素不可交互"异常?
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()
这篇关于您如何修复“元素不可交互"?例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)