@Override public <T> T until(Function<WebDriver, T> isTrue) { long end = clock.laterBy(timeOutInMillis); NotFoundException lastException = null; while (clock.isNowBefore(end)) { try { T value = isTrue.apply(driver); if (value != null && Boolean.class.equals(value.getClass())) { if (Boolean.TRUE.equals(value)) { return value; } } else if (value != null) { return value; } } catch (NotFoundException e) { // Common case in many conditions, so swallow here, but be ready to // rethrow if it the element never appears. lastException = e; } sleep(); } throwTimeoutException( String.format("Timed out after %d seconds", SECONDS.convert(timeOutInMillis, MILLISECONDS)), lastException); throw new IllegalStateException("'throwTimeoutException' should have thrown an exception!"); }