0

I'm trying to get to accept a cookie and looked at a similar question. This is how the popup looks: https://i.sstatic.net/FxChW.png I have tried different things. For instance I tried following the others question solution like so:

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC browser = webdriver.Firefox() browser.get('https://www.volkskrant.nl/best-gelezen?utm_source=pocket_mylist') wait = WebDriverWait(browser, 4) element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.message-component:nth-child(1)'))) 

This however gives the this error. I tried a bunch of different things but I can't seem to select anything on the page (at least nothing from the popup). I know this question has already been asked a couple of times but I did not find a solution. Is there anyone else who encountered this problem and knows how to just accept the cookies as to go to the regular site? thanks in advance!

2
  • I see indeed you're right! Commented Aug 20, 2021 at 15:06
  • Please don't post images of code or errors. Commented Aug 20, 2021 at 15:06

2 Answers 2

0

There's an iframe :

iframe[title='Iframe title'] 

you need to switch first in Selenium.

wait = WebDriverWait(driver, 10) wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='Iframe title']"))) 

after this you can click on accept cookies button.

full code :

driver = webdriver.Chrome(driver_path) driver.maximize_window() driver.implicitly_wait(30) driver.get("https://www.volkskrant.nl/best-gelezen?utm_source=pocket_mylist") wait = WebDriverWait(driver, 10) wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='Iframe title']"))) wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[title='Akkoord']"))).click() 
Sign up to request clarification or add additional context in comments.

Comments

0

This element is inside an iframe.
So you have first switch to that iframe and only after that you will be able to accept the cookies.

browser = webdriver.Firefox() browser.get('https://www.volkskrant.nl/best-gelezen?utm_source=pocket_mylist') wait = WebDriverWait(browser, 20) wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@src,'preload')]"))) wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[title="Akkoord"]'))).click() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.