Button/Element 不可互动

Button/Element not interactable

我正在尝试使用 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

我不知道还有什么方法可以解决。请指教,谢谢!

我同意@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();

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

到特定页面的 link 会很有帮助。