How to use lamba in Fluent Wait

774 views
Skip to first unread message

sunny sachdeva

unread,
Mar 22, 2017, 5:09:36 AM3/22/17
to webdriver
HI ,

I was using fluent waits and then upgraded webdriver version to 3.3.1 and found that lambdas has been introduced and old way of Fluent wait are no longer working


Can anyone help me in converting below fluent wait to lambda



public void waitForWebElementFluentlyPredicate(){
     
new FluentWait<WebElement>(countdown).
       withTimeout
(10, TimeUnit.SECONDS).
       pollingEvery
(100,TimeUnit.MILLISECONDS).
       
until(new Predicate<WebElement>() {
       
@Override
       
public boolean apply(WebElement element)
         
{ return element.getText().endsWith("04");
         
}
       
} );
 
}


Thanks
Sunny

⇜Krishnan Mahadevan⇝

unread,
Mar 22, 2017, 5:16:33 AM3/22/17
to webdriver
If you are using an IDE such as IntelliJ, it should help you get this converted no ?

This is what I got : 
until ((Predicate<WebElement>) element -> element.getText().endsWith("04");

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

sunny sachdeva

unread,
Mar 27, 2017, 5:09:05 AM3/27/17
to webdriver
Thanks Krishnan . In latest version of webdriver, the below code wont work since as per doc [https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG]

Remove deprecated `FluentWait.until(Predicate<?>)` method. This
  should make lambdas work properly with Wait instances now.

Hence I used the below code 
wait.until((driver)->driver.findElement(by).getText().endsWith("04"));

Thanks
Sunny Sachdeva
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

Simon Stewart

unread,
Mar 27, 2017, 4:01:23 PM3/27/17
to webdriver
Update your version of guava to version 21 or later. That'll fix the problem you're seeing.

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.

sunny sachdeva

unread,
Apr 7, 2017, 1:36:33 PM4/7/17
to webdriver
Thanks Simon this helped. But i was assuming guava version would be part of maven selenium-java. Am i missing anything?

Regards
sunny

Simon Stewart

unread,
Apr 10, 2017, 5:41:17 PM4/10/17
to webdriver
Not really. If you only have selenium as a dependency, it'll pull in the right version transitively. Otherwise, you'll be at the mercy of Maven's dependency resolution mechanisms.

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.

Neha Acharya

unread,
Jun 20, 2017, 3:44:30 AM6/20/17
to webdriver
Hi there,

I upgraded my selenium to 3.4.0 and also my guava ver to 21..still i am not able to get the fluent wait fixed.
Can anyone help me plz?
Reply all
Reply to author
Forward
0 new messages