Python Selenium Timeout Exception Catch

Viewed 73681

In my threads I use a simple variable either set to '1' or '0' to indicate if it is ready to go again. Trying to debug an issue where sometimes this isn't being reset and I think I might have it.

I didn't want connections timing out into some infinite load time (I believe the default for Selenium is not to have a timeout) so I used:

Driver.set_page_load_timeout(30)

And later on in that thread I would check

If condition:
 isrunning = 0

I had originally thought that the set_page_load_timeout would just stop it loading after 30 seconds but if I'm understanding this correctly it would actually throw an exception so I'd need to do something like:

try:
  Driver.set_page_load_timeout(30)
except:
  isrunning = 0
  Driver.Close()

-Do whatever else in function -
If condition:
  isrunning = 0
  Driver.Close()

So if it ran over 30 seconds it would close and set to 0 otherwise it would run on and get checked and set to 0 later.

I appreciate this is a tiny snippet of code but the full thing is pretty long winded and I think that's the important part.

I'd appreciate it if someone could confirm I have the right idea here. I'm all up for doing the testing but it's a problem which occurs once every 8 hours or so making it hard to pick apart but I think this potentially fits.

1 Answers
Related