为什么该元素不可交互? Python(硒)

时间:2020-01-09 17:40:09

标签: python-2.7 selenium selenium-webdriver selenium-chromedriver

我真的很难理解为什么这个元素不可交互。

我尝试使用ActionChains通过跨度文本,类名查找它。

我在做什么错了?

Python:

menu = browser.find_element_by_xpath("//span[text()='OK']").click();
actions = ActionChains(browser)
actions.move_to_element(menu)
actions.click(menu)
actions.perform()

)

enter image description here

1 个答案:

答案 0 :(得分:0)

该元素不可交互,因为它是span -通常,span元素并不意味着接受点击,它们只是包含和显示文本。您可能会比较幸运,可以尝试使用Javascript,或尝试将元素定位在跨度上方一级。我还将在按钮上调用WebDriverWait,以确保在尝试与之交互之前已正确加载了它:

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

# invoke WebDriverWait to locate the div element that is one level above the span
menu = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[span[text()='OK']]")))

# click the menu
menu.click()