Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SeleniumLibrary/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ def is_element_enabled(self, locator, tag=None):
element = self.find_element(locator, tag)
return (element.is_enabled() and
element.get_attribute('readonly') is None)

def is_visible(self, locator):
element = self.find_element(locator, required=False)
return element.is_displayed() if element else None
6 changes: 3 additions & 3 deletions src/SeleniumLibrary/keywords/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from SeleniumLibrary.base import LibraryComponent, keyword
from SeleniumLibrary.errors import ElementNotFound
from SeleniumLibrary.utils import is_noney, secs_to_timestr
from SeleniumLibrary.utils import is_noney, is_truthy, secs_to_timestr


class WaitingKeywords(LibraryComponent):
Expand Down Expand Up @@ -129,7 +129,7 @@ def wait_until_element_is_visible(self, locator, timeout=None,
``error`` can be used to override the default error message.
"""
self._wait_until(
lambda: self.find_element(locator).is_displayed(),
lambda: self.is_visible(locator),
"Element '%s' not visible after <TIMEOUT>." % locator,
timeout, error
)
Expand All @@ -147,7 +147,7 @@ def wait_until_element_is_not_visible(self, locator, timeout=None,
``error`` can be used to override the default error message.
"""
self._wait_until(
lambda: not self.find_element(locator).is_displayed(),
lambda: not self.is_visible(locator),
"Element '%s' still visible after <TIMEOUT>." % locator,
timeout, error
)
Expand Down
14 changes: 0 additions & 14 deletions test/acceptance/keywords/content_assertions.robot
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@ Get Text
... Element with locator 'missing_id' not found.
... Get Text missing_id

Element Should Be Visible
[Setup] Go To Page "visibility.html"
Element Should Be Visible i_am_visible
Run Keyword And Expect Error
... The element 'i_am_hidden' should be visible, but it is not.
... Element Should Be Visible i_am_hidden

Element Should Not Be Visible
[Setup] Go To Page "visibility.html"
Element Should Not Be Visible i_am_hidden
Run Keyword And Expect Error
... The element 'i_am_visible' should not be visible, but it is.
... Element Should Not Be Visible i_am_visible

Page Should Contain Checkbox
[Documentation] LOG 2:5 Current page contains checkbox 'can_send_email'.
[Setup] Go To Page "forms/prefilled_email_form.html"
Expand Down
48 changes: 48 additions & 0 deletions test/acceptance/keywords/element_visibility.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*** Settings ***
Resource ../resource.robot

*** Test Cases ***
Wait Until Element Is Visible
[Tags] Known Issue Internet Explorer
[Setup] Go To Page "javascript/delayed_events.html"
Run Keyword And Expect Error
... Element 'hidden' not visible after 10 milliseconds.
... Wait Until Element Is Visible hidden 0.01
Run Keyword And Expect Error
... User error message
... Wait Until Element Is Visible hidden 0.01 User error message
Wait Until Element Is Visible hidden 2 s
Run Keyword And Expect Error
... Element 'invalid' not visible after 100 milliseconds.
... Wait Until Element Is Visible invalid 0.1

Wait Until Element Is Visible with locator and error arguments
[Tags] Known Issue Internet Explorer
[Setup] Go To Page "javascript/delayed_events.html"
Wait Until Element Is Visible hidden error=My error message

Wait Until Element Is Visible with locator only
[Tags] Known Issue Internet Explorer
[Setup] Go To Page "javascript/delayed_events.html"
Wait Until Element Is Visible hidden

Wait Until Element Is Not Visible
[Setup] Go To Page "javascript/delayed_events.html"
Wait Until Element Is Not Visible id:hide_delay
Wait Until Element Is Not Visible id:not_present timeout=3

Element Should Be Visible
[Setup] Go To Page "visibility.html"
Element Should Be Visible i_am_visible
Run Keyword And Expect Error
... The element 'i_am_hidden' should be visible, but it is not.
... Element Should Be Visible i_am_hidden

Element Should Not Be Visible
[Setup] Go To Page "visibility.html"
Element Should Not Be Visible i_am_hidden
Element Should Not Be Visible not_here
Run Keyword And Expect Error
... The element 'i_am_visible' should not be visible, but it is.
... Element Should Not Be Visible i_am_visible

18 changes: 0 additions & 18 deletions test/acceptance/keywords/waiting.robot
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ Wait Until Page Does Not Contain Element
... 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' not visible after 10 milliseconds.
... Wait Until Element Is Visible hidden 0.01
Run Keyword And Expect Error
... User error message
... Wait Until Element Is Visible hidden 0.01 User error message
Wait Until Element Is Visible hidden 2 s
Run Keyword And Expect Error
... Element with locator 'invalid' not found.
... Wait Until Element Is Visible invalid 0.1

Wait Until Element Is Visible with locator and error arguments
Wait Until Element Is Visible hidden error=My error message

Wait Until Element Is Visible with locator only
Wait Until Element Is Visible hidden

Wait Until Element Is Enabled
Run Keyword And Expect Error
... Element 'id=disabled' was not enabled in 2 milliseconds.
Expand Down
10 changes: 8 additions & 2 deletions test/resources/html/javascript/delayed_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
function modifyAfterDelay() {
setTimeout('addElement()', 1000)
setTimeout('removeElement()', 1000)
setTimeout('hideElement()', 1000)
setTimeout('changeContent()', 1000)
setTimeout('changeTitle()', 1000)
setTimeout('unhideContent()', 1000)
setTimeout('enableContent()', 1000)
setTimeout('readwriteContent()', 1000)
}

function addElement() {
var div = document.createElement('div')
div.setAttribute('id', 'new div')
Expand All @@ -23,6 +24,10 @@
document.getElementById("not_present").remove()
}

function hideElement() {
document.getElementById("hide_delay").style.display = 'none';
}

function changeTitle() {
document.title = "Changed"
document.bgColor = '#FF00FF'
Expand All @@ -45,11 +50,12 @@
}
</script>
</head>

<body onload="modifyAfterDelay()">
<div id="content" style="color: white; background: red">This is content</div>
<div id="container"></div>
<div id="not_present">Element that should disappear</div>
<div id="hide_delay">Element that should set display:none</div>
<div id="hidden" style="display:none;">Initially hidden content</div>
<button id="disabled" disabled>Initially disabled content</button>
<input id="readonly" value="Initially readonly" readonly>
Expand Down