How Do You Use Explicit Wait In POM Selenium?

Dapheny Murphy | October 10, 2022

How Do You Use Explicit Wait In POM Selenium?

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")));

Disclaimer

This publication is for informational purposes only, and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment