硒元素不可交互按钮Python,Windows,Chromedriver

问题描述

错误:引发exception_class(消息,屏幕,堆栈跟踪) selenium.common.exceptions.ElementnotinteractableException:消息:元素不可交互 (会话信息:chrome = 86.0.4240.75)

我的代码:driver.find_element_by_xpath('// button [包含(text(),“立即购买”)]')。click()

html:https://i.stack.imgur.com/h0wGd.png

解决方法

由于我们没有完整的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()
,

根据硒文档,在以下情况下会发生该错误:

"Thrown when an element is present in the DOM but interactions
with that element will hit another element do to paint order"

确保您的元素是唯一标识的,然后等待。如果还不够,请通过JavaScript执行点击操作。