Basically, there are two types of waits and they are as follows: explicit wait and implicit wait. The code for the explicit wait is as follows:
WebDriverWait.until(condition-that-finds-the-element);
The code for the implicit wait is as follows:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
You can analyze the difference in detail here.
public WebElement fluentWait(final By locator) {
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
});
return foo;
}
Usage of fluentWait in your case will be something like the following:
WebElement textbox = fluentWait(By.id("textbox"));
Hope this helps!
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s online automation testing training!