I've been struggling with this for some time now I want to consent to the pop-up but selenium just doesn't want to click the consent button
I have tried:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'/html/body/div[2]/div[2]/div[1]/div[2]/div[2]/button[1]/p'))).click()
and
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"/html/body/div[2]")))
cookie = wait.until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[2]/div[2]/div[1]/div[2]/div[2]/button[1]")))
cookie.click()
CodePudding user response:
EDIT: Another try (but again, I cannot test it):
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "fc-cta-consent"))).click()
CodePudding user response:
To click on the element Consent you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.fc-consent-root button[aria-label='Consent'] p.fc-button-label"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='fc-consent-root']//button[@aria-label='Consent']//p[@class='fc-button-label' and text()='Consent']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC