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.

1
  • So when I go to cookiebot.com you just want to hit the allow all right? Commented Dec 5, 2021 at 21:29

1 Answer 1

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
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.