question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Wait until does not contain element` always waits for full amount of wait time

See original GitHub issue

Hello,

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:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bartklcommented, Mar 29, 2019

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 to find_element going on which adheres to the implicit_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 of implicit_wait in this context.

But I think I stated my case. At the least I learned something, thanks for explanation.

1reaction
aaltatcommented, Mar 29, 2019

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 is implicit wait which is Selenium level timeout. The implicit wait will control how long Selenium will wait element to appear and by defining implicit wait, user/SeleniumLibrary gives waiting control to Selenium how long is waited to the element to appear. This will overrule the timeout 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

is there any alternative to 'Wait Until Page Does Not Contain ...
It works but waits for complete 30 seconds even if the UI Overlay disappears in initial 1-2 seconds. Thsi results in long execution...
Read more >
Selenium Wait Commands : Implicit, Explicit & Fluent Wait
Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, ......
Read more >
Waits - Selenium
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element...
Read more >
Everything You Need to Know About Waits in Selenium
In the above code, I have given Implicit Wait as 20 seconds, which implies the maximum wait time is 20 seconds for the...
Read more >
Selenium Wait – Implicit, Explicit and Fluent Waits - Guru99
The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found