您如何解决“元素不可交互"的问题?例外? [英] How do you fix the "element not interactable" exception?

查看:640
本文介绍了您如何解决“元素不可交互"的问题?例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被问过很多次了,但是如何解决元素不可交互"的异常呢?

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()

这篇关于您如何解决“元素不可交互"的问题?例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆