Skip to content

Provide alternative to ElementQuery.waitForFirst #2189

@sissbruecker

Description

@sissbruecker

ElementQuery.waitForFirst has been deprecated, presumably to guide users to use single() instead, which is a more specific query. The JavaDoc for the deprecation mentions to write a custom wait loop and use single(). However, looking at the implementation for waitForFirst users would have to replace this one liner with quite a bit of (Selenium) code and exception handling:

        T result = new WebDriverWait(getDriver(),
                Duration.ofSeconds(timeOutInSeconds)).until(driver -> {
                    try {
                        return first();
                    } catch (NoSuchElementException e) {
                        return null;
                    }
                });
        if (result == null) {
            throw new NoSuchElementException(getNoSuchElementMessage(null));
        } else {
            return result;
        }

There should be an alternative for ElementQuery.waitForFirst that does not require implementing the above manually, or at least the deprecation notice should provide a proper solution for how to implement this yourself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    Status
    🪵Product backlog
    Status
    Maybe

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions