0

I have the following code that should click a cookie button. But for some reason it gives the error that is given below. Can someone tell me why It can't be clicked while the EC for the explicit wait is literally 'element_to_be_clickable'?

PATH = 'C:\Program Files (x86)\Chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.set_page_load_timeout(100)
driver.get(URL)


WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'accept-cookie-consent')))
driver.find_element_by_class_name('nlportal-cookie-consent-button').click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'accept-cookie-consent')))
driver.find_element_by_class_name('nlportal-cookie-consent-button').click()


WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'content-loader__load-more-link')))
driver.find_element_by_class_name('content-loader__load-more-link').click()

This is the error I get:

    Traceback (most recent call last):
  File "C:\Users\axelz\PycharmProjects\ArbitrageBetting\ABFootball\ABBL\BLBookies\ABBLToto.py", line 5, in <module>
    array = Toto(URL, 'Bundesliga')
  File "C:\Users\axelz\PycharmProjects\ArbitrageBetting\ABFootball\ABFootballPackage\BookieFunctions.py", line 101, in Toto
    driver.find_element_by_class_name('nlportal-cookie-consent-button').click()
  File "C:\Users\axelz\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\axelz\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\axelz\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\axelz\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="nlportal-cookie-consent-button" type="button" id="accept-cookie-consent">...</button> is not clickable at point (77, 666). Other element would receive the click: <button class="nlportal-cookie-consent-button" type="button" id="accept-cookie-consent">...</button>
  (Session info: chrome=92.0.4515.159)

2 Answers 2

1

Few things to be noted down here :

  1. Launch the browser in full screen mode.

    driver.maximize_window()
    
  2. When you use WebDriverWait, like this :

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'accept-cookie-consent')))
    

it returns a webelement, so you do not have to separately call driver.find_element_by_class_name('nlportal-cookie-consent-button').click()

instead you can perform .click() on WebDriverWait command directly.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'accept-cookie-consent'))).click()
  1. You can give it a try with ActionsChain as well.

    from selenium.webdriver.common.action_chains import ActionChains
    ActionChains(driver).move_to_element(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'accept-cookie-consent')))).click().perform()
    

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

0

you are doing everything very difficult, simplify everything, you will be happy!

wait.until(EC.visibility_of_element_located((By.ID, '#nlportal-cookie-consent-button'))).click()

1 Comment

Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.

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.