Python + Selenium: Wait until element is fully loaded

First of all I strongly believe you were pretty close. You simply need to format your code in a Pythonic which may solve your issue straight away as follows :

WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="accountStandalone"]/div/div/div[2]/div/div/div[1]/button'))).click()

You have pulled a rug over the actual issue by mentioning it doesn’t wait until it found but goes instant and does other stuff which it shouldn’t rather than mentioning what your program is supposed to do (e.g. your code trials) and what wrong your program is doing (i.e. error stack trace).

As per the HTMLs you have shared you can induce a waiter for either of the WebElements as follows :

  • Waiter for the visibility of the text NU ÄR DU MEDLEM, Hello. :

    • CSS_SELECTOR :

      WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.confirmation-title.nsg-font-family--platform.nsg-text--black.edf-title-font-size--xlarge.js-confirmationTitle")))
      
    • XPATH :

      WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class="confirmation-title nsg-font-family--platform nsg-text--black edf-title-font-size--xlarge js-confirmationTitle" and contains(.,'NU ÄR DU MEDLEM, Hello.')]")))
      
  • Waiter for the button with text FORTSÄTT :

    • CSS_SELECTOR :

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.nsg-button.nsg-bg--black.register-next-step-cta.js-nextStepCta")))
      
    • XPATH :

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class="nsg-button nsg-bg--black register-next-step-cta js-nextStepCta" and contains(.,'FORTSÄTT')]")))
      

Leave a Comment