Skip to content

Instantly share code, notes, and snippets.

@santiycr
Created July 26, 2011 17:57
Show Gist options
  • Save santiycr/1107375 to your computer and use it in GitHub Desktop.
Save santiycr/1107375 to your computer and use it in GitHub Desktop.
Implicit wait Selenium 1
import time, re
from selenium import selenium
class implicitWaitSelenium(selenium):
"""
Extending the regular selenium class to add implicit waits
"""
def __init__(self, *args):
self.implicit_wait = 30
super(implicitWaitSelenium, self).__init__(*args)
def do_command(self, verb, args, implicit_wait=None):
if implicit_wait is None:
implicit_wait = self.implicit_wait
try:
return super(implicitWaitSelenium, self).do_command(verb, args)
except Exception, e:
if (re.match("ERROR: Element .* not found", str(e))
and implicit_wait > 0):
time.sleep(1)
return self.do_command(verb, args, implicit_wait-1)
raise Exception(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment