Skip to content

Commit e5ca153

Browse files
committed
Add 'Wait Until Page Not Contains Element' -keyword
1 parent c0ed09a commit e5ca153

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/Selenium2Library/keywords/_waiting.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ def wait_until_page_contains_element(self, locator, timeout=None, error=None):
6262
error = "Element '%s' did not appear in <TIMEOUT>" % locator
6363
self._wait_until(timeout, error, self._is_element_present, locator)
6464

65+
def wait_until_page_not_contains_element(self, locator, timeout=None, error=None):
66+
"""Waits until element specified with `locator` disappears from current page.
67+
68+
Fails if `timeout` expires before the element disappears. See
69+
`introduction` for more information about `timeout` and its
70+
default value.
71+
72+
`error` can be used to override the default error message.
73+
74+
See also `Wait Until Page Contains`, `Wait For Condition`,
75+
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
76+
Keyword Succeeds`.
77+
"""
78+
def check_present():
79+
present = self._is_element_present(locator)
80+
if not present:
81+
return
82+
else:
83+
return error or "Element '%s' did not disappear in %s" % (locator, self._format_timeout(timeout))
84+
self._wait_until_no_error(timeout, check_present)
85+
6586
def wait_until_element_is_visible(self, locator, timeout=None, error=None):
6687
"""Waits until element specified with `locator` is visible.
6788
@@ -154,4 +175,4 @@ def _wait_until_no_error(self, timeout, wait_func, *args):
154175

155176
def _format_timeout(self, timeout):
156177
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
157-
return robot.utils.secs_to_timestr(timeout)
178+
return robot.utils.secs_to_timestr(timeout)

test/acceptance/keywords/waiting.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Wait Until Page Contains Element
1717
Wait Until Page Contains Element new div 2 seconds
1818
Run Keyword And Expect Error Element '%cnon-existent' did not appear in 100 milliseconds Wait Until Page Contains Element %cnon-existent 0.1 seconds
1919

20+
Wait Until Page Not Contains Element
21+
[Documentation] Tests also that format characters (e.g. %c) are handled correctly in error messages
22+
Wait Until Page Not Contains Element not_present 2 seconds
23+
Run Keyword And Expect Error Element 'content' did not disappear in 100 milliseconds Wait Until Page Not Contains Element content 0.1 seconds
24+
2025
Wait Until Element Is Visible
2126
Run Keyword And Expect Error Element 'hidden' was not visible in 100 milliseconds Wait Until Element Is Visible hidden 0.1
2227
Wait Until Element Is Visible hidden 2 s
@@ -27,5 +32,4 @@ Wait Until Element Is Enabled
2732
Run Keyword And Expect Error Element 'id=disabled' was not enabled in 100 milliseconds Wait Until Element Is Enabled id=disabled 0.1
2833
Wait Until Element Is Enabled id=disabled 2 s
2934
Run Keyword And Expect Error Element locator 'id=invalid' did not match any elements after 100 milliseconds Wait Until Element Is Enabled id=invalid 0.1
30-
Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message
31-
35+
Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message

test/resources/html/javascript/delayed_events.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script type="text/javascript">
55
function modifyAfterDelay() {
66
setTimeout('addElement()', 1000)
7+
setTimeout('removeElement()', 1000)
78
setTimeout('changeContent()', 1000)
89
setTimeout('changeTitle()', 1000)
910
setTimeout('unhideContent()', 1000)
@@ -16,7 +17,11 @@
1617
div.innerHTML = 'New Element'
1718
document.getElementById("container").appendChild(div)
1819
}
19-
20+
21+
function removeElement() {
22+
document.getElementById("not_present").remove()
23+
}
24+
2025
function changeTitle() {
2126
document.title = "Changed"
2227
document.bgColor = '#FF00FF'
@@ -38,7 +43,8 @@
3843
<body onload="modifyAfterDelay()">
3944
<div id="content">This is content</div>
4045
<div id="container"></div>
46+
<div id="not_present">Element that should disappear</div>
4147
<div id="hidden" style="display:none;">Inititally hidden content</div>
4248
<button id="disabled" disabled>Inititally disabled content</button>
4349
</body>
44-
</html>
50+
</html>

0 commit comments

Comments
 (0)