`Wait until does not contain element` always waits for full amount of wait time
See original GitHub issueHello,
A colleague of mine stumbled upon this, and I found it to be worthy of creating an issue.
Let’s say implicit wait is set to 20s, and suppose I want to wait for the disappearance of the element iDontExist
:
*** Settings ***
Library SeleniumLibrary implicit_wait=20.0
*** Test Cases ***
Testing implicit wait
Open browser http://www.google.com chrome
Wait until page does not contain element //iDontExist
This will result in a full 20 seconds wait until it returns successfully. I inspected the code responsible, and indeed, it reflects the finding exactly:
@keyword
def wait_until_page_does_not_contain_element(self, locator, timeout=None,
error=None):
"""Waits until element ``locator`` disappears from current page.
Fails if ``timeout`` expires before the element disappears. See
the `Timeouts` section for more information about using timeouts and
their default value and the `Locating elements` section for details
about the locator syntax.
``error`` can be used to override the default error message.
"""
self._wait_until(
lambda: self.find_element(locator, required=False) is None,
"Element '%s' did not disappear in <TIMEOUT>." % locator,
timeout, error
)
In my opinion that is not intuitive. I would expect this keyword to return as soon as the element is not found. Maybe there’s use cases for the current implementation also, in which case maybe a parameter can distinguish between both behaviors or something?
I just wanted to bring this to your attention and I’m curious to the clarification.
Thanks, Bart
My environment:
Browser: Chrome 73.0.3683.86 (64 bits) Browser driver: ChromeDriver version 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) Operating System: Windows 10 version 1703 (build 15063.1631) Libraries
- Robot Framework: 3.1.1
- Selenium: 3.141.0
- SeleniumLibrary: 3.3.1
- Interpreter: Python 2.7.16 (v2.7.16:413a49145e) (64 bits)
PS Judging by the implementation I would expect this to occur regardless of using implicit or explicit wait.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Ah yes, I like how your explanation takes into account both possible waiting parameters. That’s crucial!
Personally I would still find it to be clarifying if there’s explicit mentioning of this counter-intuitive effect when using those
Wait until ... not ...
keywords, like my example explanation above. People, like I did, might not realize there’s an internal call tofind_element
going on which adheres to theimplicit_wait
value (if set). They might think, like I did, that maybe some custom logic has been applied and not be aware of the effects ofimplicit_wait
in this context.But I think I stated my case. At the least I learned something, thanks for explanation.
I agree that it is not very intuitive, but there is logical explanation. SeleniumLibrary supports two type of timeouts. There is
timeout
which is SeleniumLibrary level timeout and there isimplicit wait
which is Selenium level timeout. Theimplicit wait
will control how long Selenium will wait element to appear and by definingimplicit wait
, user/SeleniumLibrary gives waiting control to Selenium how long is waited to the element to appear. This will overrule thetimeout
which is SeleniumLibrary level timeout.Selenium API does not contain a method which would allow to ask that element is not in the page, in the Selenium API there is only way to ask that element is in the page. Now because you are waiting that element does not appear in the page, then Selenium will always wait the
implicit wait
amount to element to appear.If only
timeout
is defined, which is by default 5 seconds, keyword will return immediately when the element is not in the DOM.