0

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()
9
  • Hello every one ! :)
    – Alexis
    Feb 7 at 13:56
  • What do mean by "doesn't work"? What are trying to achieve and what issue are going through? Feb 7 at 15:38
  • To click to the accept cookies button we need to do a switch to frame before. The problème is theWebDriverWait in the second assertion The following code work :
    – Alexis
    Feb 7 at 17:35
  • WebDriverWait(driver, 30).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "gdpr-consent-notice")))
    – Alexis
    Feb 7 at 17:38
  • time.sleep(1)
    – Alexis
    Feb 7 at 17:41

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.