TestProject Forum
Powered by leading experts in the test automation community

How do Implicit Waits work?

I’ve been reading multiple articles about implicit waits as well as .sleep(). Currently I am using .sleep() in multiple steps and want to improve this. I think implicit might be the best solution, but I have a question. If I have this code set:

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Does that mean it waits the full 30 seconds between each step or if it finds the element before 30 seconds it continues to the next step? How does it work?

implicitlyWait will wait up to the time limit when the driver is searching for elements using the findElement and findElements methods. The driver will poll the DOM every 500 milliseconds until the element is found or the time has run out.
You can also use explicit wait with expected conditions to wait for specific conditions, for example if you want to wait for the element to be visible rather than just present in the DOM like in implicit wait. It will also wait up to 30 seconds for the element to be visible. For example

WebElement element = new WebDriverWait(driver, 30)

Unlike the implicit wait, where you only need to define it one time for the driver instance, the explicit wait need to be called every time you use it, so best practice is to warp it in a method that can be called when necessary.

1 Like