Skip to content

Instantly share code, notes, and snippets.

@jlggross
Last active July 30, 2020 22:15
Show Gist options
  • Save jlggross/ed4328e25fd76f6bd238adbf1250d8b4 to your computer and use it in GitHub Desktop.
Save jlggross/ed4328e25fd76f6bd238adbf1250d8b4 to your computer and use it in GitHub Desktop.
Waiting the element to be created
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
xpath = "/html/body/app-root/div/app-variable-sale/section/app-variable-assets-list/section/div/div[2]/div/ul/li[1]"
# Wait 20 seconds until the element is created
try:
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, xpath)))
except TimeoutException:
print("Timeout!")
# Now it works!
elements = driver.find_elements_by_xpath(xpath[:-3])
for element in elements:
print(element.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment