按钮不可使用selenium python单击

按钮不可使用selenium python单击,python,selenium,selenium-webdriver,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,我一直试图使用selenium单击一个按钮,但它一直说该元素是不可交互的,即使它在屏幕上是可见的,我可以手动单击它。我尝试过webdriverwait、隐式等待和许多其他解决方案,但似乎都不起作用。请任何人提供一个解决方案。 我已经附加了按钮代码和我自己的代码 import time from selenium import webdriver from selenium.webdriver.chrome.options import Options browser = webdriver.C

我一直试图使用selenium单击一个按钮,但它一直说该元素是不可交互的,即使它在屏幕上是可见的,我可以手动单击它。我尝试过webdriverwait、隐式等待和许多其他解决方案,但似乎都不起作用。请任何人提供一个解决方案。 我已经附加了按钮代码和我自己的代码

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options 
browser = webdriver.Chrome('')
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-popup-blocking")
browser.implicitly_wait(10)
browser.get('https://www.aldi.co.uk/kirkton-house-high-back-desk-chair/p/709360437078000')
browser.maximize_window()
buybutton = False

while not buybutton:
    try:
        addToCartBtn = addButton = browser.find_element_by_class_name('disabled')
        print("Button isn't ready yet.")
        time.sleep(1)
        browser.refresh()
    except:
        time.sleep(2)
        addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="addToBasketButton"]')
        addToCartBtn.click()
        
     
        buybutton = True

加入篮子

xpath
一起使用的ID
addToBasketButton
有两个web元素:

请改用此CSS_选择器:

ul.product-details__list.product-details__list--errors+form div.product-details__selectButton button
请尝试以下xpath:

driver.find_element_by_xpath(".//ul[contains(@class,'errors')]//following::form[contains(@class,'product-form')]//button[@id='addToBasketButton']").click()