Selenium Java Lambda Implementation for Explicit Waits

I am trying to implement Java Lambda concept for selenium webdriver waits. I need to convert custom webdriver wait something like this

  (new WebDriverWait(driver(), 5))
            .until(new ExpectedCondition<WebElement>() {
                public WebElement apply(WebDriver d) {
                    return d.findElement(By.linkText(""));


 (new WebDriverWait(driver(), 5)).until((driver) -> driver.findElement(By.linkText("")));

But it does not matches the functional interface of ‘until’ refers to and throws error.

So i tried passing the Lambda as it supports.


Predicate<WebDriver> isVisible = (dr) -> dr.findElement(

It kind of works but is not what i require because it returns only void.

Need your help or advice on this.


The problem is with your syntax.The below worked perfectly for me

WebElement wer = new WebDriverWait(driver, 5).until((WebDriver dr1) -> dr1.findElement("q")));

Your code Problem

 //What is this driver() is this a function that returns the driver or what
 //You have to defined the return type of driver variable in until() function
 //And you cant use the same  variable names in both new WebdriverWait() and until() see my syntax

(new WebDriverWait(driver(), 5)).until((driver) -> driver.findElement(By.linkText("")));

Leave a Reply

Your email address will not be published. Required fields are marked *