I want to find out the number of raised exceptions and use it with if statement. To be more clear: If it raises more than 10 TimeoutException following one after another, print "There is a problem with website". I searched for it but I couldn't find anything. I hope there is a efficent way to do this.
Here is the code:
while True:
try:
browser.get("url")
return
except selenium.common.exceptions.TimeoutException:
print "Timeout"
What I want to do is: If it raises more than 10 Timeout exceptions, print "There is a problem with website"
Just keep track of the number of times the exception has been raised in a counter. Try something like:
count = 1
while True:
try:
browser.get("url")
except selenium.common.exceptions.TimeoutException:
count += 1
if count >= 10:
print 'There is a problem with website'
break
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.