慕运维8079593
该元素Tout Accepter位于 an 内<iframe>,因此您必须:诱导WebDriverWait等待所需的框架可用并切换到它。诱导WebDriverWait以使所需元素可单击。您可以使用以下任一定位器策略:使用CSS_SELECTOR:driver.get('http://www.legorafi.fr/')WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"div#appconsent>iframe")))WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.button--filled>span.baseText"))).click()使用XPATH:driver.get('http://www.legorafi.fr/')WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//div[@id='appconsent']/iframe")))WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'button--filled')]/span[contains(@class, 'baseText')]"))).click()注意:您必须添加以下导入:from selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as EC浏览器快照: