【问题标题】:Button/Element not interactable按钮/元素不可交互
【发布时间】:2021-09-13 04:27:41
【问题描述】:

我正在尝试使用Seleniumxpath 单击网页中的按钮。我设法点击了上一页中的一个按钮,但是在加载到这个新页面后,我尝试使用相同的代码但不同的按钮 HTML,它无法像以前那样加载。

我的代码如下:

driver = webdriver.Chrome() 
driver.get("https://connect.com")
driver.find_element_by_xpath("//button[@class='p-button p-component']").click() #button workable


In the next page:
driver.find_element_by_xpath("//button[@class='add icon-only proto-button ng-star-inserted']").click() #button not working

我收到的错误信息是:

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

我也尝试过如下添加等待时间,但还是不行。

button = WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, "//button[@class='add icon-only proto-button ng-star-inserted']")))
button.click()

但是,现在我收到的错误信息是:

selenium.common.exceptions.TimeoutException: Message: 

例如,我也尝试过处理 HTML 代码的其他元素。但无论哪种方式,按钮都不起作用。

driver.find_element_by_xpath("//span[text()='proto-icon ng-star-inserted']").click()

or

driver.find_element_by_xpath("//connect-button[@class='proto-button-list-item ng-star-inserted']").click()

The HTML is in the picture attached

我不知道我还能如何解决。请指教,谢谢!

【问题讨论】:

  • 我猜/button/connect-button 覆盖,所以它不可点击。你试过用 JSclick 点击它吗?
  • 嗨@lucasnguyen17,我对Python和Selenium真的很陌生,我不太确定该怎么做。你能大致告诉我它的样子吗?是的,从 HTML 中可以看到 /connect-button 在 /button 元素上方。
  • 好的,我想我需要凭据才能在这里登录 brandforce.com/domain/connect.com ?如果是这样,我没有它们。请分享您要点击的按钮的 HTML?
  • @ejbeh element = driver.find_element_by_xpath("//button[@class='p-button p-component']") driver.execute_script("arguments[0].click();", element)
  • 感谢@lucasnguyen17 我已经尝试使用element = driver.find_element_by_xpath("//button[@class='add icon-only proto-button ng-star-inserted']") 并且它有效

标签: python selenium button xpath


【解决方案1】:

我同意@lucasnguyen17

按钮element 必须不可点击,因为它上面有connect-button 元素。

所以

element = driver.find_element_by_xpath("//button[@class='p-button p-component']") 
driver.execute_script("arguments[0].click();", element)

其实很简单,

在第一行中,它将元素存储为 python 变量。 然后运行js脚本。

element.click();

元素是您的特定按钮。你可以在控制台上试试看是否有效。

指向特定页面的链接会很有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 2019-10-19
    • 2021-10-20
    • 2021-07-08
    • 2021-08-02
    • 2021-04-29
    • 1970-01-01
    相关资源
    最近更新 更多