I am learning selenum with python and the explicit wait method doesn't work to click on the 'accept cookies' button. Otherwise, the time.sleep method work and I would like to understant why the explicit wait method doersn't work. I typed this code : (sorry for my bad english, I'm french...)
driver.get("https://demo.guru99.com/test/newtours/")
driver.maximize_window()
WebDriverWait(driver, 30).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "gdpr-consent-notice")))
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="save"]/span[1]/div/span'))).click()
1 Answer 1
Why do you want to use the explicit wait? Selenium by default has a timeout when you use findelement, that I think it's about 10 seconds. If you want to know more about this issue, I found that website(blog). https://blog.devgenius.io/browser-automation-with-python-and-selenium-5-waits-4b9e4636548c or that other https://selenium-python.readthedocs.io/waits.html
WebDriverWait(driver, 30).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "gdpr-consent-notice")))
time.sleep(1)