Skip to content

Commit e85fcd7

Browse files
committed
Merge pull request #375 from molsky/wait_until_page_not_contains_element2
Add 'Wait Until Page Does Not Contain Element' keyword
2 parents 0fc0373 + 7d4965f commit e85fcd7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/Selenium2Library/keywords/_waiting.py

Lines changed: 21 additions & 0 deletions
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_does_not_contain_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

test/acceptance/keywords/waiting.txt

Lines changed: 5 additions & 0 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 Does Not Contain Element
21+
[Documentation] Tests also that format characters (e.g. %c) are handled correctly in error messages
22+
Wait Until Page Does Not Contain Element not_present 2 seconds
23+
Run Keyword And Expect Error Element 'content' did not disappear in 100 milliseconds Wait Until Page Does Not Contain 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

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)