20
20
from selenium .common .exceptions import StaleElementReferenceException
21
21
from selenium .common .exceptions import WebDriverException
22
22
from selenium .common .exceptions import NoAlertPresentException
23
+ from selenium .webdriver .remote .webdriver import WebElement
23
24
24
25
"""
25
26
* Canned "Expected Conditions" which are generally useful within webdriver
@@ -259,11 +260,14 @@ class invisibility_of_element_located(object):
259
260
locator used to find the element
260
261
"""
261
262
def __init__ (self , locator ):
262
- self .locator = locator
263
+ self .target = locator
263
264
264
265
def __call__ (self , driver ):
265
266
try :
266
- return _element_if_visible (_find_element (driver , self .locator ), False )
267
+ target = self .target
268
+ if not isinstance (target , WebElement ):
269
+ target = _find_element (driver , target )
270
+ return _element_if_visible (target , False )
267
271
except (NoSuchElementException , StaleElementReferenceException ):
268
272
# In the case of NoSuchElement, returns true because the element is
269
273
# not present in DOM. The try block checks if the element is present
@@ -273,6 +277,16 @@ def __call__(self, driver):
273
277
return True
274
278
275
279
280
+ class invisibility_of_element (invisibility_of_element_located ):
281
+ """ An Expectation for checking that an element is either invisible or not
282
+ present on the DOM.
283
+
284
+ element is either a locator (text) or an WebElement
285
+ """
286
+ def __init (self , element ):
287
+ self .target = element
288
+
289
+
276
290
class element_to_be_clickable (object ):
277
291
""" An Expectation for checking an element is visible and enabled such that
278
292
you can click it."""
0 commit comments