我真的很难理解为什么这个元素是不可交互的。
我尝试过通过span文本、类名、使用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()


发布于 2020-01-10 01:48:09
元素是不可交互的,因为它是一个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()https://stackoverflow.com/questions/59669474
复制相似问题