Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the EpectedCondition invisibility_of_element #6163

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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