【问题标题】:Why is this element not interactable? Python (Selenium) [duplicate]为什么这个元素不可交互? Python(硒)[重复]
【发布时间】:2020-04-27 09:12:05
【问题描述】:

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

我已经尝试通过跨度文本、类名、使用 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()

【问题讨论】:

  • 运行脚本时遇到什么错误?

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


【解决方案1】:

该元素不可交互,因为它是一个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()

【讨论】:

    猜你喜欢
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多