3

I want to know how to replace popular WebDriverWait with lambda.

It is used for explicitly wait some event.

Code snippet:

(new WebDriverWait(Driver.driver.get(), 10)).until(new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver d) {
        return d.findElement(By.id("DataTables_Table_0_processing")).isDisplayed();
    }
});

Or:

(new WebDriverWait(Driver.driver.get(), 10))
        .until(ExpectedConditions
                .invisibilityOfElementLocated(By.id("DataTables_Table_0_processing")));

How to replace it with lambda expression?

1
  • If you're doing this in IDE, every decent modern IDE have a quick-fix or refactoring like "convert anonymous class to lambda expression". Just hit it, and you'll be fine. Commented Sep 26, 2015 at 11:45

1 Answer 1

3
(new WebDriverWait(Driver.driver.get(), 10))
        .until(d -> d.findElement(By.id("DataTables_Table_0_processing")).isDisplayed());

I don't think the second case would be improved with a lambda since there's already a convenience method which provides sufficient clarity.

Sign up to request clarification or add additional context in comments.

1 Comment

What should we use instead of WebDriverWait in Selenium 4.2 and above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.