Skip to content

Instantly share code, notes, and snippets.

@tinytengu
Created September 18, 2021 15:19
Show Gist options
  • Save tinytengu/5e4b347ca4ccda5baf3dc41075cd0f53 to your computer and use it in GitHub Desktop.
Save tinytengu/5e4b347ca4ccda5baf3dc41075cd0f53 to your computer and use it in GitHub Desktop.
Selenium wait for element
# Source: https://stackoverflow.com/a/26567563
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
browser = webdriver.Firefox()
browser.get("url")
delay = 3 # seconds
try:
myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'IdOfMyElement')))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment