消息:元素不可交互。 Xpath正确

Message: element not interactable. Xpath correct

如何点击?显然我可以用鼠标,然后出现一个新的面具。单击 () 时出现以下错误。

显然 Xpath 是正确的,实际上它报告了以下代码 =

driver.find_element_by_xpath("//span[@class='example']")
<selenium.webdriver.remote.webelement.WebElement (session="9e25c2b4350ca89b8da611a6dc63ae0c", element="f8dc7d1a-a31a-4fc8-98ec-34ff5a7fa12e")>

此消息错误:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

使用 WebDriverWait() 并等待 element_to_be_clickable()

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//span[@class='example']"))).click()

您需要导入以下库

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By