Software Development and QA Tips By QASource Experts

How Do You Use Explicit Wait In POM Selenium?

Written by Dapheny Murphy | Oct 10, 2022 4:00:00 PM

Waits undoubtedly play a crucial role in Selenium framework implementation. However, it is quite necessary that waits should be used efficiently to get the best performance of test suites while scripting executions.

While performing any action using Selenium, the user needs to wait for a certain amount of time so that elements of the page can be loaded properly and to avoid fake failures.

Basic imports required for explicit wait are:

import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait

So to declare the explicit wait, "ExpectedConditions" and "WebDriverWait" are required to be used.

To initialize the wait object use the following code:

WebDriverWait wait = new WebDriverWait(driver,30);

And ultimately it can be used like this:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Element Locator")));