My synchronisation strategies with WebDriver have generally revolved around the WebDriverWait and creating custom ExpectedCondition objects.
When I first saw the FluentWait, I dismissed it as a slightly more customisable version of the WebDriverWait.
But then I looked more closely at the signature of the constructor, and I noticed the Generics being used.
The use of Generics means I don’t have to pass in a WebDriver, I could use a WebElement, or a By, or anything I want really.
Which could prove really handy for Ajaxy apps.
The code waits for the element to become visible using a WebDriverWait then drops down to a lower level of granularity to check that the seconds count down to 04
Note in the above code I tell FluentWait that it will be sending a <WebElement> through to the apply method.
FluentWait can take a Predicate, or a Function, as an argument in the until method.
I chose to use a Function, which can return any object, I chose to return a Boolean.
A predicate will only return a boolean.
FluentWait can prove pretty handy for Ajax because of the flexibility you have for ignoring exceptions and easily tweaking the wait and polling times.
You can learn about the differences between Function and Predicate from the guava-libraries documentation.
I have uploaded the code for this example to github, in the uploaded code I also have an example of using the Predicate.