19
19
from selenium .common .exceptions import TimeoutException
20
20
21
21
POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method
22
- IGNORED_EXCEPTIONS = [NoSuchElementException ] # list of exceptions ignored during calls to the method
22
+ IGNORED_EXCEPTIONS = [NoSuchElementException ] # list of exceptions ignored during calls to the method
23
23
24
24
class WebDriverWait (object ):
25
25
26
26
def __init__ (self , driver , timeout , poll_frequency = POLL_FREQUENCY , ignored_exceptions = None ):
27
27
"""Constructor, takes a WebDriver instance and timeout in seconds.
28
-
28
+
29
29
:Args:
30
30
- driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote)
31
31
- timeout - Number of seconds before timing out
@@ -50,7 +50,7 @@ def __init__(self, driver, timeout, poll_frequency=POLL_FREQUENCY, ignored_excep
50
50
if ignored_exceptions is not None :
51
51
try :
52
52
exceptions .extend (iter (ignored_exceptions ))
53
- except TypeError : # ignored_exceptions is not iterable
53
+ except TypeError : # ignored_exceptions is not iterable
54
54
exceptions .append (ignored_exceptions )
55
55
self ._ignored_exceptions = tuple (exceptions )
56
56
@@ -71,17 +71,17 @@ def until(self, method, message=''):
71
71
raise TimeoutException (message )
72
72
73
73
def until_not (self , method , message = '' ):
74
- """Calls the method provided with the driver as an argument until the \
75
- return value is False."""
76
- end_time = time .time () + self ._timeout
77
- while (True ):
78
- try :
79
- value = method (self ._driver )
80
- if not value :
81
- return value
82
- except self ._ignored_exceptions :
83
- return True
84
- time .sleep (self ._poll )
85
- if (time .time () > end_time ):
86
- break
87
- raise TimeoutException (message )
74
+ """Calls the method provided with the driver as an argument until the \
75
+ return value is False."""
76
+ end_time = time .time () + self ._timeout
77
+ while (True ):
78
+ try :
79
+ value = method (self ._driver )
80
+ if not value :
81
+ return value
82
+ except self ._ignored_exceptions :
83
+ return True
84
+ time .sleep (self ._poll )
85
+ if (time .time () > end_time ):
86
+ break
87
+ raise TimeoutException (message )
0 commit comments