Home > Software design >  Cannot click on cookie banner button using Selenium
Cannot click on cookie banner button using Selenium

Time:05-13

I am unable to click the cookie accept button on this site: https://www.verivox.de/privathaftpflicht/

This is the code I used:

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.verivox.de/privathaftpflicht/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="uc-btn-accept-banner"]'))).click()

It simply does nothing, no error message. The banner just stays there.

CodePudding user response:

The button to accept the cookies is contained in the object div.cmp-container, which has the property display: table, so you can get rid of the banner by simply setting it to none:

banner = driver.find_element(By.CSS_SELECTOR, 'div.cmp-container')
driver.execute_script("arguments[0].style.display = 'none';", banner)
  • Related