diff --git a/src/Selenium2Library/keywords/_waiting.py b/src/Selenium2Library/keywords/_waiting.py index 565e11867..a40fb8983 100644 --- a/src/Selenium2Library/keywords/_waiting.py +++ b/src/Selenium2Library/keywords/_waiting.py @@ -62,6 +62,27 @@ def wait_until_page_contains_element(self, locator, timeout=None, error=None): error = "Element '%s' did not appear in " % locator self._wait_until(timeout, error, self._is_element_present, locator) + def wait_until_page_does_not_contain_element(self, locator, timeout=None, error=None): + """Waits until element specified with `locator` disappears from current page. + + Fails if `timeout` expires before the element disappears. See + `introduction` for more information about `timeout` and its + default value. + + `error` can be used to override the default error message. + + See also `Wait Until Page Contains`, `Wait For Condition`, + `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until + Keyword Succeeds`. + """ + def check_present(): + present = self._is_element_present(locator) + if not present: + return + else: + return error or "Element '%s' did not disappear in %s" % (locator, self._format_timeout(timeout)) + self._wait_until_no_error(timeout, check_present) + def wait_until_element_is_visible(self, locator, timeout=None, error=None): """Waits until element specified with `locator` is visible. diff --git a/test/acceptance/keywords/waiting.txt b/test/acceptance/keywords/waiting.txt index 909532d8f..ce7227eb4 100644 --- a/test/acceptance/keywords/waiting.txt +++ b/test/acceptance/keywords/waiting.txt @@ -17,6 +17,11 @@ Wait Until Page Contains Element Wait Until Page Contains Element new div 2 seconds Run Keyword And Expect Error Element '%cnon-existent' did not appear in 100 milliseconds Wait Until Page Contains Element %cnon-existent 0.1 seconds +Wait Until Page Does Not Contain Element + [Documentation] Tests also that format characters (e.g. %c) are handled correctly in error messages + Wait Until Page Does Not Contain Element not_present 2 seconds + Run Keyword And Expect Error Element 'content' did not disappear in 100 milliseconds Wait Until Page Does Not Contain Element content 0.1 seconds + Wait Until Element Is Visible Run Keyword And Expect Error Element 'hidden' was not visible in 100 milliseconds Wait Until Element Is Visible hidden 0.1 Wait Until Element Is Visible hidden 2 s diff --git a/test/resources/html/javascript/delayed_events.html b/test/resources/html/javascript/delayed_events.html index 8b3bf4c04..9e40c48e0 100644 --- a/test/resources/html/javascript/delayed_events.html +++ b/test/resources/html/javascript/delayed_events.html @@ -4,6 +4,7 @@