Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div id="loader-mid" style="position: absolute; top: 118.5px; left: 554px; display: none;">
- <div class="a">Loading</div>
- <div class="b">please wait...</div>
- </div>
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.wait import WebDriverWait
- self.wait = WebDriverWait(driver, 10)
- self.wait.until(EC.invisibility_of_element_located((By.XPATH, "//*[@id='loader_mid'][contains(@style, 'display: block')]")))
- self.wait.until_not(EC.presence_of_element_located((By.XPATH, "//*[@id='loader_mid'][contains(@style, 'display: block')]")))
- SHORT_TIMEOUT = 5 # give enough time for the loading element to appear
- LONG_TIMEOUT = 30 # give enough time for loading to finish
- LOADING_ELEMENT_XPATH = '//*[@id="xPath"]/xPath/To/The/Loading/Element'
- try:
- # wait for loading element to appear
- # : need to make sure we don't prematurely check if element
- # : has disappeared before it has had a chance to appear
- WebDriverWait(
- driver, SHORT_TIMEOUT
- ).until(EC.presence_of_element_located((By.XPATH, LOADING_ELEMENT_XPATH)))
- # then wait for it to disappear
- WebDriverWait(
- driver, LONG_TIMEOUT
- ).until_not(EC.presence_of_element_located((By.XPATH, LOADING_ELEMENT_XPATH)))
- except TimeoutException:
- # if timeout exception was raised - should be safe to assume loading has finished.
- # : However this may not always be the case, use with caution, othwise handle appropriately.
- pass
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.common.exceptions import TimeoutException
- while True:
- try:
- WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, 'your_xpath')))
- except TimeoutException:
- break
Add Comment
Please, Sign In to add comment