Guest User

Untitled

a guest
May 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <div id="loader-mid" style="position: absolute; top: 118.5px; left: 554px; display: none;">
  2. <div class="a">Loading</div>
  3. <div class="b">please wait...</div>
  4. </div>
  5.  
  6. from selenium.webdriver.support import expected_conditions as EC
  7. from selenium.webdriver.common.by import By
  8. from selenium.webdriver.support.wait import WebDriverWait
  9.  
  10. self.wait = WebDriverWait(driver, 10)
  11.  
  12. self.wait.until(EC.invisibility_of_element_located((By.XPATH, "//*[@id='loader_mid'][contains(@style, 'display: block')]")))
  13.  
  14. self.wait.until_not(EC.presence_of_element_located((By.XPATH, "//*[@id='loader_mid'][contains(@style, 'display: block')]")))
  15.  
  16. SHORT_TIMEOUT = 5 # give enough time for the loading element to appear
  17. LONG_TIMEOUT = 30 # give enough time for loading to finish
  18. LOADING_ELEMENT_XPATH = '//*[@id="xPath"]/xPath/To/The/Loading/Element'
  19.  
  20. try:
  21. # wait for loading element to appear
  22. # : need to make sure we don't prematurely check if element
  23. # : has disappeared before it has had a chance to appear
  24. WebDriverWait(
  25. driver, SHORT_TIMEOUT
  26. ).until(EC.presence_of_element_located((By.XPATH, LOADING_ELEMENT_XPATH)))
  27.  
  28. # then wait for it to disappear
  29. WebDriverWait(
  30. driver, LONG_TIMEOUT
  31. ).until_not(EC.presence_of_element_located((By.XPATH, LOADING_ELEMENT_XPATH)))
  32.  
  33. except TimeoutException:
  34. # if timeout exception was raised - should be safe to assume loading has finished.
  35. # : However this may not always be the case, use with caution, othwise handle appropriately.
  36. pass
  37.  
  38. from selenium.webdriver.common.by import By
  39. from selenium.webdriver.support.ui import WebDriverWait
  40. from selenium.webdriver.support import expected_conditions as EC
  41. from selenium.common.exceptions import TimeoutException
  42.  
  43. while True:
  44. try:
  45. WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, 'your_xpath')))
  46. except TimeoutException:
  47. break
Add Comment
Please, Sign In to add comment