【发布时间】:2020-10-12 17:29:50
【问题描述】:
错误:引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 (会话信息:chrome=86.0.4240.75)
我的代码:driver.find_element_by_xpath('//button[contains(text(),"Buy Now")]').click()
【问题讨论】:
错误:引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 (会话信息:chrome=86.0.4240.75)
我的代码:driver.find_element_by_xpath('//button[contains(text(),"Buy Now")]').click()
【问题讨论】:
由于我们没有完整的HTML 页面来查找准确的xpath,并且我们有代码的小屏幕截图,您可以尝试使用不同的xpath 技术来查找元素。
//button[@class='button bits' and contains(., 'Buy Now')]
然后,您可以使用以下选项之一获取该元素并单击它。
选项 1
driver.find_element(By.XPATH, "//button[@class='button bits' and contains(., 'Buy Now')]").click()
选项 2
driver.find_element(By.XPATH, "//button[@class='button bits' and contains(text(), 'Buy Now')]").click()
【讨论】:
根据 selenium 文档,该错误发生在以下情况:
"Thrown when an element is present in the DOM but interactions
with that element will hit another element do to paint order"
确保您的元素是唯一标识并使用等待。如果还不够,请通过 JavaScript 执行点击操作。
【讨论】: