Created
July 26, 2011 17:57
-
-
Save santiycr/1107375 to your computer and use it in GitHub Desktop.
Implicit wait Selenium 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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