WebDriverWait.until() gets hung, don't know why

469 views
Skip to first unread message

Nick Klauer

unread,
Mar 7, 2011, 5:20:00 PM3/7/11
to webd...@googlegroups.com
I'm using WebDriverWait to check for the presence of some elements (namely <iframes>) and it seems that it gets hung up and won't return at all. I could be using the class wrong, so I've attached the little bit of code that I've used to construct the waiting for element:

    public static List<WebElement> iframeTags(WebDriver driver) {
        return new WebDriverWait(driver, 30, 1000).until(new Function<WebDriver, List<WebElement>>() {
            public List<WebElement> apply(WebDriver driver) {
                return driver.findElements(By.tagName("iframe"));
            }
        });
    }
    ...

    final By iframe = By.tagName("iframe");
    List<WebElement> eles = iframeTags(driver);

Now, I'm trying to make sense of whether the timeout would occur at all, since I have never seen it actually throw an exception after a period of time.  It either works, or sits there and waits until the End of Days.  What am I doing wrong, or what could I be missing that would let this test work more consistently? 


Daniel Wagner-Hall

unread,
Mar 7, 2011, 5:56:24 PM3/7/11
to webd...@googlegroups.com, Nick Klauer
That code should always return immediately - WebDriverWait waits until
what is returned doesn't throw a NotFoundException, and doesn't
evaluate to false (where null evaluates to false). findElements will
return an empty List<WebElement> if none are present, and an empty
list isn't null. You may want to try implementing your own Wait class
modelled on https://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java
which has empty-list logic, rather than null logic...

> --
> You received this message because you are subscribed to the Google Groups
> "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to
> webdriver+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/webdriver?hl=en.
>

Nick Klauer

unread,
Mar 7, 2011, 7:32:49 PM3/7/11
to webd...@googlegroups.com, Nick Klauer
So if what you say is true:
WebDriverWait waits until what is returned doesn't throw a NotFoundException, and doesn't evaluate to false (where null evaluates to false).
then why would it hang at all?  I can check for an empty list if it returns, and I have gotten empty lists back before.  What I'm confused about is why it would not return at all, even after the timeout.  Does the WebDriverWait(driver, <seconds>, <sleepMillis>) not throw an exception after <seconds> passes?  Does it not return at all, even if the time passes?

Daniel Wagner-Hall

unread,
Mar 8, 2011, 5:08:50 PM3/8/11
to webd...@googlegroups.com, Nick Klauer
Sounds like some other issue - if you execute the findElements not
wrapped in the wait, can you make it hang?

Reply all
Reply to author
Forward
0 new messages