【问题标题】:Selenium - Element not interactableSelenium - 元素不可交互
【发布时间】:2021-08-27 06:49:43
【问题描述】:

在这个问题上需要帮助。我研究过的所有解决方案/建议都无法解决。

尝试使用 Selenium 单击按钮。不断收到这些错误。 selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLButtonElement] has no size and location 和selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我不明白为什么这个元素不可交互。

    play_button = driver.find_element_by_xpath('//*[@id="ppp"]/div/div[2]/div[2]/div[2]/button')
    driver.implicitly_wait(10)
    ActionChains(driver).move_to_element(play_button).click(play_button).perform()

打印时play_button = <selenium.webdriver.remote.webelement.WebElement (session="ca50b37ee2e4b194b2ad5305e254079f", element="78e35dc3-fef8-4082-a6e4-0a92dfbf2ec6")>

我已经尝试过WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ppp"]/div/div[2]/div[2]/div[2]/button'))),但这会超时。元素永远不会变成可点击的。

我尝试过使用完整的 xpath。

我已尝试禁用扩展/最大化窗口驱动程序选项。

元素不在框架或任何东西中。它位于身体中的 div 中。 该元素可在 Chrome 的控制台中点击。

任何信息/建议都会有所帮助。 谢谢。

【问题讨论】:

  • 我已经建议了一些答案,但如果你能分享页面链接会更好

标签: python selenium selenium-chromedriver


【解决方案1】:

您尝试单击的按钮已隐藏,即使使用 JavaScript 执行程序也无法单击。
您可以在该页面上点击开始视频

driver.find_element_by_css_selector('div.player-poster.clickable').click()

或

driver.find_element_by_css_selector('div.play-wrapper').click()

无需使用ActionChains(driver).move_to_element等
只需单击一下即可。
只是不要忘记设置

driver.implicitly_wait(10)

或者在访问元素之前使用预期条件的显式等待来使页面加载。

【讨论】:

  • 第一个解决方案 - 在 .move_to_element 上给出与element not interactable: [object HTMLButtonElement] has no size and location 相同的错误
  • 第二个解决方案 - 什么也没做.....这是否意味着该元素不可点击?令人困惑的是我可以在 Chrome 的控制台中获取元素并单击它,但在弹出 js 时不能?同上。感谢您的建议。
  • 也许它在 iframe 中?可以分享一个链接吗?
  • 尝试点击这个css_selector div.player-poster.clickable
  • 你试图点击的按钮是隐藏的,即使是JS也无法点击
猜你喜欢
  • 2021-08-02
  • 2020-03-08
  • 2021-12-16
  • 2021-04-22
  • 1970-01-01
  • 1970-01-01
  • 2021-08-21
  • 2019-04-19
  • 1970-01-01
相关资源
最近更新 更多