diff --git a/src/SeleniumLibrary/base/context.py b/src/SeleniumLibrary/base/context.py index e210d6606..dd1418970 100644 --- a/src/SeleniumLibrary/base/context.py +++ b/src/SeleniumLibrary/base/context.py @@ -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 diff --git a/src/SeleniumLibrary/keywords/waiting.py b/src/SeleniumLibrary/keywords/waiting.py index 644e17c04..539667fed 100644 --- a/src/SeleniumLibrary/keywords/waiting.py +++ b/src/SeleniumLibrary/keywords/waiting.py @@ -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): @@ -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 ." % locator, timeout, error ) @@ -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 ." % locator, timeout, error ) diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index cc81b59d0..7624de11f 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -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" diff --git a/test/acceptance/keywords/element_visibility.robot b/test/acceptance/keywords/element_visibility.robot new file mode 100644 index 000000000..029475ac3 --- /dev/null +++ b/test/acceptance/keywords/element_visibility.robot @@ -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 + diff --git a/test/acceptance/keywords/waiting.robot b/test/acceptance/keywords/waiting.robot index 9d2456a78..827002d1f 100644 --- a/test/acceptance/keywords/waiting.robot +++ b/test/acceptance/keywords/waiting.robot @@ -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. diff --git a/test/resources/html/javascript/delayed_events.html b/test/resources/html/javascript/delayed_events.html index 85793d262..cf5978596 100644 --- a/test/resources/html/javascript/delayed_events.html +++ b/test/resources/html/javascript/delayed_events.html @@ -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') @@ -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' @@ -45,11 +50,12 @@ } - +
This is content
Element that should disappear
+
Element that should set display:none