Can't locate element on Pop-Up Window using Selenium on Python Can't locate element on Pop-Up Window using Selenium on Python selenium selenium

Can't locate element on Pop-Up Window using Selenium on Python


Every time you launch your webdriver you're using a new temporary profile. That profile has no cookies therefore it's seen by the site as a new user an needs to accept the cookie message.

I had a look at your site and to close the message you need to switch iframe. You were close with your solution, it might just be it needed a different method of selecting the frame...

This code works for me:

from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bydriver = webdriver.Chrome()driver.get("https://www.duden.de/rechtschreibung/aussuchen")iframe = driver.find_element_by_xpath("//iframe[contains(@id,'sp_message_iframe')]")driver.switch_to.frame(iframe)cookieAccpet = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='AKZEPTIEREN']")))cookieAccpet.click()driver.switch_to.default_content()

Remember to switch back to the default frame at the end with driver.switch_to.default_content(), then you can continue your script.