首页 > 解决方案 > selenium.common.exceptions.ElementNotInteractableException:消息:不显示元素

问题描述

<DIV class="x-grid3-cell-inner x-grid3-col-column16" style="CURSOR: pointer" unselectable="on">IMG title="Copy password" style="FLOAT: left; MARGIN: 0px 3px 0px 0px; DISPLAY: block" src="images/icons/password_copy.gif" border=0></DIV>

试图通过

elem = driver.find_element_by_xpath("//img[@src='images/icons/password_copy.gif']") 
Or elem = driver.find_element_by_xpath("//img[@title='Copy password']")

Elem.click()- 不工作但无法单击该元素。得到错误:

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element is not displayed.

有人可以给我解决方法吗

标签: pythonseleniumselenium-webdriver

解决方案


解决此问题的方法是使用 Selenium 中提供的 ActionChains

from selenium.webdriver.common.action_chains import ActionChains
elem = driver.find_element #complete xpath
action = ActionChains(driver)
action.move_to_element_with #complete where you want to move element
action.click()
action.perform()

您可以阅读有关 XPath ActionChains 文档的更多信息。


推荐阅读