Implicit waits work under the assumption that the element(s) we are searching for might take some time to appear on the DOM. Hence, an implicit wait will wait for every element that is part of our automation script.
On the other hand, explicit waits allow us to control the automation script flow for one or more specific elements, and under predefined conditions. The WebDriverWait and ExpectedConditions classes are used for setting explicit waits. The following lines set a 5-second explicit wait until the title of the page contains the string "Explicit". Note that if the title is updated before the 5-second waiting time, the automation script will continue to the next step:
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.titleContains("Explicit"));
It is important to highlight that explicit waits act only...