0

I need to find a way to click on the cookie agreement button created by the javascript code that is provided by cookiebot.com such as the following example in a HTML code,

<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid="8123486-d5f-ec" data-blockingmode="auto" type="text/javascript"></script>

I have searched the net, but there is no example showing how to do that using Selenium Python.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Rasoul
  • 3,758
  • 5
  • 26
  • 34

1 Answers1

1

To click() on the element Allow all you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://www.cookiebot.com/en/")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click()
    
  • Using XPATH:

    driver.get("https://www.cookiebot.com/en/")   
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352