Selenium Wait Until Element Ready (Python)

December 22, 2018

Wait until element presence by class name

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

el = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "confirmation-box"))
)

NOTE: By supports ID, CSS_SELECTOR, NAME, etc.

Wait until element ready to be clicked

el = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CLASS_NAME, "confirmation-button"))
)

NOTE: expected_conditions supports invisibility_of_element, visibility_of, title_is, url_changes, etc.

If you just want to wait without any conditions.

import time
timer.sleep(1)

You can set an implicit wait (it will automatically wait n seconds for any elements not available immediately).

driver.implicitly_wait(10)
driver.get("https://www.wikipedia.org/")
english_link = driver.find_element_by_css_selector("#js-link-box-en")

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.