Created
September 18, 2021 15:19
-
-
Save tinytengu/5e4b347ca4ccda5baf3dc41075cd0f53 to your computer and use it in GitHub Desktop.
Selenium wait for element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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