Skip to content

Commit

Permalink
[py] Added ExpectedCondition invisibility_of_element
Browse files Browse the repository at this point in the history
  • Loading branch information
larkost authored and davehunt committed Jul 31, 2018
1 parent 0248a49 commit 7842db3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions py/selenium/webdriver/support/expected_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from selenium.common.exceptions import StaleElementReferenceException
from selenium.common.exceptions import WebDriverException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webdriver import WebElement

"""
* Canned "Expected Conditions" which are generally useful within webdriver
Expand Down Expand Up @@ -259,11 +260,14 @@ class invisibility_of_element_located(object):
locator used to find the element
"""
def __init__(self, locator):
self.locator = locator
self.target = locator

def __call__(self, driver):
try:
return _element_if_visible(_find_element(driver, self.locator), False)
target = self.target
if not isinstance(target, WebElement):
target = _find_element(driver, target)
return _element_if_visible(target, False)
except (NoSuchElementException, StaleElementReferenceException):
# In the case of NoSuchElement, returns true because the element is
# not present in DOM. The try block checks if the element is present
Expand All @@ -273,6 +277,16 @@ def __call__(self, driver):
return True


class invisibility_of_element(invisibility_of_element_located):
""" An Expectation for checking that an element is either invisible or not
present on the DOM.
element is either a locator (text) or an WebElement
"""
def __init(self, element):
self.target = element


class element_to_be_clickable(object):
""" An Expectation for checking an element is visible and enabled such that
you can click it."""
Expand Down
12 changes: 12 additions & 0 deletions py/test/selenium/webdriver/common/webdriverwait_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ def testExpectedConditionFrameToBeAvailableAndSwitchToItByLocator(driver, pages)
assert 'click me' == driver.find_element_by_id('alertInFrame').text


def testExpectedConditionInvisiblityOfElement(driver, pages):
pages.load("javascriptPage.html")
target = driver.find_element_by_id('clickToHide')
driver.execute_script("delayedShowHide(0, true)")
with pytest.raises(TimeoutException):
WebDriverWait(driver, 0.7).until(EC.invisibility_of_element(target))
driver.execute_script("delayedShowHide(200, false)")
element = WebDriverWait(driver, 0.7).until(EC.invisibility_of_element(target))
assert element.is_displayed() is False
assert target == element


def testExpectedConditionInvisiblityOfElementLocated(driver, pages):
pages.load("javascriptPage.html")
driver.execute_script("delayedShowHide(0, true)")
Expand Down

0 comments on commit 7842db3

Please sign in to comment.