Skip to content

Commit 0ae6ab7

Browse files
authored
Fixes Wait Until Element Is Not Visible keyword (robotframework#1009)
* Fixes Wait Until Element Is Not Visible keyword robotframework#1008
1 parent b448e76 commit 0ae6ab7

6 files changed

Lines changed: 63 additions & 37 deletions

File tree

src/SeleniumLibrary/base/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ def is_element_enabled(self, locator, tag=None):
8585
element = self.find_element(locator, tag)
8686
return (element.is_enabled() and
8787
element.get_attribute('readonly') is None)
88+
89+
def is_visible(self, locator):
90+
element = self.find_element(locator, required=False)
91+
return element.is_displayed() if element else None

src/SeleniumLibrary/keywords/waiting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from SeleniumLibrary.base import LibraryComponent, keyword
2020
from SeleniumLibrary.errors import ElementNotFound
21-
from SeleniumLibrary.utils import is_noney, secs_to_timestr
21+
from SeleniumLibrary.utils import is_noney, is_truthy, secs_to_timestr
2222

2323

2424
class WaitingKeywords(LibraryComponent):
@@ -129,7 +129,7 @@ def wait_until_element_is_visible(self, locator, timeout=None,
129129
``error`` can be used to override the default error message.
130130
"""
131131
self._wait_until(
132-
lambda: self.find_element(locator).is_displayed(),
132+
lambda: self.is_visible(locator),
133133
"Element '%s' not visible after <TIMEOUT>." % locator,
134134
timeout, error
135135
)
@@ -147,7 +147,7 @@ def wait_until_element_is_not_visible(self, locator, timeout=None,
147147
``error`` can be used to override the default error message.
148148
"""
149149
self._wait_until(
150-
lambda: not self.find_element(locator).is_displayed(),
150+
lambda: not self.is_visible(locator),
151151
"Element '%s' still visible after <TIMEOUT>." % locator,
152152
timeout, error
153153
)

test/acceptance/keywords/content_assertions.robot

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,6 @@ Get Text
145145
... Element with locator 'missing_id' not found.
146146
... Get Text missing_id
147147

148-
Element Should Be Visible
149-
[Setup] Go To Page "visibility.html"
150-
Element Should Be Visible i_am_visible
151-
Run Keyword And Expect Error
152-
... The element 'i_am_hidden' should be visible, but it is not.
153-
... Element Should Be Visible i_am_hidden
154-
155-
Element Should Not Be Visible
156-
[Setup] Go To Page "visibility.html"
157-
Element Should Not Be Visible i_am_hidden
158-
Run Keyword And Expect Error
159-
... The element 'i_am_visible' should not be visible, but it is.
160-
... Element Should Not Be Visible i_am_visible
161-
162148
Page Should Contain Checkbox
163149
[Documentation] LOG 2:5 Current page contains checkbox 'can_send_email'.
164150
[Setup] Go To Page "forms/prefilled_email_form.html"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
*** Settings ***
2+
Resource ../resource.robot
3+
4+
*** Test Cases ***
5+
Wait Until Element Is Visible
6+
[Tags] Known Issue Internet Explorer
7+
[Setup] Go To Page "javascript/delayed_events.html"
8+
Run Keyword And Expect Error
9+
... Element 'hidden' not visible after 10 milliseconds.
10+
... Wait Until Element Is Visible hidden 0.01
11+
Run Keyword And Expect Error
12+
... User error message
13+
... Wait Until Element Is Visible hidden 0.01 User error message
14+
Wait Until Element Is Visible hidden 2 s
15+
Run Keyword And Expect Error
16+
... Element 'invalid' not visible after 100 milliseconds.
17+
... Wait Until Element Is Visible invalid 0.1
18+
19+
Wait Until Element Is Visible with locator and error arguments
20+
[Tags] Known Issue Internet Explorer
21+
[Setup] Go To Page "javascript/delayed_events.html"
22+
Wait Until Element Is Visible hidden error=My error message
23+
24+
Wait Until Element Is Visible with locator only
25+
[Tags] Known Issue Internet Explorer
26+
[Setup] Go To Page "javascript/delayed_events.html"
27+
Wait Until Element Is Visible hidden
28+
29+
Wait Until Element Is Not Visible
30+
[Setup] Go To Page "javascript/delayed_events.html"
31+
Wait Until Element Is Not Visible id:hide_delay
32+
Wait Until Element Is Not Visible id:not_present timeout=3
33+
34+
Element Should Be Visible
35+
[Setup] Go To Page "visibility.html"
36+
Element Should Be Visible i_am_visible
37+
Run Keyword And Expect Error
38+
... The element 'i_am_hidden' should be visible, but it is not.
39+
... Element Should Be Visible i_am_hidden
40+
41+
Element Should Not Be Visible
42+
[Setup] Go To Page "visibility.html"
43+
Element Should Not Be Visible i_am_hidden
44+
Element Should Not Be Visible not_here
45+
Run Keyword And Expect Error
46+
... The element 'i_am_visible' should not be visible, but it is.
47+
... Element Should Not Be Visible i_am_visible
48+

test/acceptance/keywords/waiting.robot

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ Wait Until Page Does Not Contain Element
4646
... Element 'content' did not disappear in 100 milliseconds.
4747
... Wait Until Page Does Not Contain Element content 0.1 seconds
4848

49-
Wait Until Element Is Visible
50-
Run Keyword And Expect Error
51-
... Element 'hidden' not visible after 10 milliseconds.
52-
... Wait Until Element Is Visible hidden 0.01
53-
Run Keyword And Expect Error
54-
... User error message
55-
... Wait Until Element Is Visible hidden 0.01 User error message
56-
Wait Until Element Is Visible hidden 2 s
57-
Run Keyword And Expect Error
58-
... Element with locator 'invalid' not found.
59-
... Wait Until Element Is Visible invalid 0.1
60-
61-
Wait Until Element Is Visible with locator and error arguments
62-
Wait Until Element Is Visible hidden error=My error message
63-
64-
Wait Until Element Is Visible with locator only
65-
Wait Until Element Is Visible hidden
66-
6749
Wait Until Element Is Enabled
6850
Run Keyword And Expect Error
6951
... Element 'id=disabled' was not enabled in 2 milliseconds.

test/resources/html/javascript/delayed_events.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
function modifyAfterDelay() {
66
setTimeout('addElement()', 1000)
77
setTimeout('removeElement()', 1000)
8+
setTimeout('hideElement()', 1000)
89
setTimeout('changeContent()', 1000)
910
setTimeout('changeTitle()', 1000)
1011
setTimeout('unhideContent()', 1000)
1112
setTimeout('enableContent()', 1000)
1213
setTimeout('readwriteContent()', 1000)
1314
}
14-
15+
1516
function addElement() {
1617
var div = document.createElement('div')
1718
div.setAttribute('id', 'new div')
@@ -23,6 +24,10 @@
2324
document.getElementById("not_present").remove()
2425
}
2526

27+
function hideElement() {
28+
document.getElementById("hide_delay").style.display = 'none';
29+
}
30+
2631
function changeTitle() {
2732
document.title = "Changed"
2833
document.bgColor = '#FF00FF'
@@ -45,11 +50,12 @@
4550
}
4651
</script>
4752
</head>
48-
53+
4954
<body onload="modifyAfterDelay()">
5055
<div id="content" style="color: white; background: red">This is content</div>
5156
<div id="container"></div>
5257
<div id="not_present">Element that should disappear</div>
58+
<div id="hide_delay">Element that should set display:none</div>
5359
<div id="hidden" style="display:none;">Initially hidden content</div>
5460
<button id="disabled" disabled>Initially disabled content</button>
5561
<input id="readonly" value="Initially readonly" readonly>

0 commit comments

Comments
 (0)