1

I've tried almost everything and searched on SO but can't get passed the cookie accept on gmx.com. Hoping someone can help out. So far I've tried:

driver = webdriver.Chrome(CHROMEPATH)
driver.get('https://www.gmx.com')
time.sleep(5)
cookie_accept = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="onetrust-accept-btn-handler"]')))
cookie_accept.click()

===AND===

driver = webdriver.Chrome(CHROMEPATH)
driver.get('https://www.gmx.com')
wait = WebDriverWait(driver, 15)
wait.until(EC.element_to_be_clickable(
    (By.CSS_SELECTOR, "div[style='onetrust-style'] button[id*='onetrust-accept-btn-handler']")))
driver.find_element_by_css_selector("div[style='onetrust-style'] button[id*='onetrust-accept-btn-handler']").click()
time.sleep(10)
driver.quit()

What am I doing wrong?! Any help is greatly appreciated!!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

The element Agree and continue is within nested elements so you have to:

  • Induce WebDriverWait for the parent frame to be available and switch to it.

  • Induce WebDriverWait for the child frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get("https://www.gmx.com/consentpage")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.permission-core-iframe")))
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://plus.gmx.com/lt']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#onetrust-accept-btn-handler"))).click()
      
    • Using XPATH:

      driver.get("https://www.gmx.com/consentpage")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='permission-core-iframe']")))
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@src, 'https://plus.gmx.com/lt')]")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).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
    
  • Browser Snapshot:

GMX


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • You should define a `wait` object only once, not 3 times. – Prophet Dec 16 '21 at 17:31
  • 1
    WOW THANK YOU SO MUCH – ok-programmer Dec 16 '21 at 17:32
  • @Prophet _You should define a wait object only once, not 3 times_ : Where are you coming from? Any documentation to support your comment? Why would the _GC_ mechanism implemented? – undetected Selenium Dec 16 '21 at 17:43
  • @DebanjanB I don't know about official documentation about this. I just know that I wrote an answer like this with several initializations of wait object and some other user with quite wrote me that this is not the correct way. It also seems to me to be logically correct – Prophet Dec 16 '21 at 17:52
1

This element is inside an iframe. iframe inside iframe. So you have to switch to the inner iframe in order to access that element.
Something like this:

driver.get("https://www.gmx.com/consentpage")  
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.permission-core-iframe")))  
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src,'plus')]")))
wait.until(EC.visibility_of_element_located((By.XPATH, '//button[@id="onetrust-accept-btn-handler"]'))).click()

Prophet
  • 32,350
  • 22
  • 54
  • 79