Reputation: 67
I am using selenium to scrape web. The web is similar to google map, I need to input a start location and end location and then get the results. The webpage loads slowly and sometimes stops responding. so I try use WebDriverWait to catch a timeout exception and restart the webpage.
However, in fact if the webpage stops responding, the webDriverWait does not throw timeout exception and the code just gets stuck forever. For example, last time, my code stuck at invisibility_of_element_located and does not respond even the timeout is set to 10s.
WebDriverWait(driver,10).until(EC.invisibility_of_element_located((By.XPATH, "//*[@ng-show='route.isCalculating']")))
Upvotes: 0
Views: 1527
Reputation: 5909
You could try wrapping the wait in a try / except block to see if you can catch the TimeOutException
:
from selenium.common.exceptions import TimeoutException
try:
print("Attempting to locate element")
WebDriverWait(driver,10).until(EC.invisibility_of_element_located((By.XPATH, "//*[@ng-show='route.isCalculating']")))
except TimeoutException:
print("TimeoutException encountered")
print("Task complete")
Based on what prints out in the console, you probably determine whether or not the exception is hit at all.
If TimeoutException
is not caught, you can just use except:
and see if anything is being caught at all.
Upvotes: 1