Last active
July 30, 2020 22:15
-
-
Save jlggross/ed4328e25fd76f6bd238adbf1250d8b4 to your computer and use it in GitHub Desktop.
Waiting the element to be created
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
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