diff --git a/common/src/web/hidden_partially.html b/common/src/web/hidden_partially.html new file mode 100644 index 0000000000000..f0f9fe5b8a677 --- /dev/null +++ b/common/src/web/hidden_partially.html @@ -0,0 +1,45 @@ + + + + + + + + + + + diff --git a/py/selenium/webdriver/support/expected_conditions.py b/py/selenium/webdriver/support/expected_conditions.py index a9860298cf4a9..de3ff512c0302 100644 --- a/py/selenium/webdriver/support/expected_conditions.py +++ b/py/selenium/webdriver/support/expected_conditions.py @@ -101,6 +101,18 @@ def __init__(self, locator): def __call__(self, driver): return _find_elements(driver, self.locator) + +class visibility_of_all_elements_located(object): + """ An expectation for checking that there is at least one element visible + on a web page. + locator is used to find the element + returns the list of WebElements once they are located + """ + def __init__(self, locator): + self.locator = locator + + def __call__(self, driver): + return [element for element in _find_elements(driver, self.locator) if _element_if_visible(element)] class text_to_be_present_in_element(object): """ An expectation for checking if the given text is present in the diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index 7fe23f4ea8bdf..cb34e5ef962aa 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -72,12 +72,25 @@ def testShouldExplicitlyWaituntilAtLeastOneElementIsFoundWhenSearchingForMany(se def testShouldFailToFindElementsWhenExplicitWaiting(self): self._loadPage("dynamic") - try: + with self.assertRaises(TimeoutException): elements = WebDriverWait(self.driver, 0.7).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "redbox"))) - except TimeoutException as e: - pass # we should get a timeout - except Exception as e: - self.fail("Expected TimeoutException but got " + str(e)) + + def testShouldWaitUntilAtLeastOneVisibleElementsIsFoundWhenSearchingForMany(self): + self._loadPage("hidden_partially") + add_visible = self.driver.find_element_by_id("addVisible") + add_hidden = self.driver.find_element_by_id("addHidden") + + add_visible.click() + add_visible.click() + add_hidden.click() + + elements = WebDriverWait(self.driver, 2).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox"))) + self.assertTrue(len(elements) == 2) + + def testShouldFailToFindVisibleElementsWhenExplicitWaiting(self): + self._loadPage("hidden_partially") + with self.assertRaises(TimeoutException): + elements = WebDriverWait(self.driver, 0.7).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "redbox"))) def testShouldWaitOnlyAsLongAsTimeoutSpecifiedWhenImplicitWaitsAreSet(self): self._loadPage("dynamic")