Skip to content

Commit 7842db3

Browse files
larkostdavehunt
authored andcommitted
[py] Added ExpectedCondition invisibility_of_element
1 parent 0248a49 commit 7842db3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

py/selenium/webdriver/support/expected_conditions.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from selenium.common.exceptions import StaleElementReferenceException
2121
from selenium.common.exceptions import WebDriverException
2222
from selenium.common.exceptions import NoAlertPresentException
23+
from selenium.webdriver.remote.webdriver import WebElement
2324

2425
"""
2526
* Canned "Expected Conditions" which are generally useful within webdriver
@@ -259,11 +260,14 @@ class invisibility_of_element_located(object):
259260
locator used to find the element
260261
"""
261262
def __init__(self, locator):
262-
self.locator = locator
263+
self.target = locator
263264

264265
def __call__(self, driver):
265266
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)
267271
except (NoSuchElementException, StaleElementReferenceException):
268272
# In the case of NoSuchElement, returns true because the element is
269273
# not present in DOM. The try block checks if the element is present
@@ -273,6 +277,16 @@ def __call__(self, driver):
273277
return True
274278

275279

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+
276290
class element_to_be_clickable(object):
277291
""" An Expectation for checking an element is visible and enabled such that
278292
you can click it."""

py/test/selenium/webdriver/common/webdriverwait_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ def testExpectedConditionFrameToBeAvailableAndSwitchToItByLocator(driver, pages)
222222
assert 'click me' == driver.find_element_by_id('alertInFrame').text
223223

224224

225+
def testExpectedConditionInvisiblityOfElement(driver, pages):
226+
pages.load("javascriptPage.html")
227+
target = driver.find_element_by_id('clickToHide')
228+
driver.execute_script("delayedShowHide(0, true)")
229+
with pytest.raises(TimeoutException):
230+
WebDriverWait(driver, 0.7).until(EC.invisibility_of_element(target))
231+
driver.execute_script("delayedShowHide(200, false)")
232+
element = WebDriverWait(driver, 0.7).until(EC.invisibility_of_element(target))
233+
assert element.is_displayed() is False
234+
assert target == element
235+
236+
225237
def testExpectedConditionInvisiblityOfElementLocated(driver, pages):
226238
pages.load("javascriptPage.html")
227239
driver.execute_script("delayedShowHide(0, true)")

0 commit comments

Comments
 (0)