phdj
phdj

Reputation: 199

Try statement inside loop not being executed after first pass when exception thrown

I'm having selenium grab a url that is occasionally flaky in that the page doesn't load, so I want selenium to try the url again. Similar to a user clicking on a link that hangs the first time, so they click it again.

My issue is when the first "driver.get" doesn't work, it throws the TimeoutException, goes back to the top of the loop and instead of "try"ing again, it runs through the loop and exits the loop. Can someone shed some light on this? Please and thank you. :)

Some additional notes: I only get one "Timed out" print, so it seems the try statement is only being executed once. I get all five numbers from my iterator printed.

driver2.set_page_load_timeout(6)
for k in range(0, 5, +1):
     print k
     try:
         driver2.get(url)
     except TimeoutException:
         print "Timed out"

Upvotes: 0

Views: 90

Answers (1)

phdj
phdj

Reputation: 199

Nothing is wrong with the above question. Only the fact that I wasn't checking success of the "driver.get()" which was apparently succeeding every subsequent pass.

Upvotes: 1

Related Questions