I have tried several different options to try get Selenium to accept cookies on a certain page.
Option 1)
AcceptCookiesAC = web.find_element(By.XPATH,"//*[@id='ccc-notify-accept']")
web.execute_script("arguments[0].click();", AcceptCookiesAC)
Option 2)
wait = WebDriverWait(web, 20)
#Accept Cookies
AcceptCookiesAC = wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@id='ccc-notify-accept']")))
web.execute_script("arguments[0].click();", AcceptCookiesAC)
print("Accepted Cookies")
Neither of these methods are working and I get the following error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="ch-btn ch-btn--success ch-display--flex ch-mh--auto sm:ch-width--6 md:ch-width--5 ch-width--12 lg:ch-width--4 false" type="button">...</button> is not clickable at point (599, 567). Other element would receive the click: <div id="ccc-notify" class="ccc-notify__notify ccc-content--light " role="dialog" aria-labelledby="ccc-notify-title">...</div>
How can I get around this? Starting to infuriate me and I have tried so many options.
Its strange, but if you try to click on Yes, I'm happy manually, you will notice that you need to click thrice for the button to be clicked. You need to do the same in your script as well, that click on the button three times.
Refer the working code below:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://www.arnoldclark.com/sell-my-car')
driver.maximize_window()
wait = WebDriverWait(driver, 15)
wait.until(EC.element_to_be_clickable((By.ID, "registration"))).send_keys("<enter reg no>")
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Get my quote']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()=\"Yes, I'm happy\"]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()=\"Yes, I'm happy\"]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()=\"Yes, I'm happy\"]"))).click()
time.sleep(10)