Hi Inder, you can use Explicit wait in any automation test script in the following manner:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExplicitWaitDemo {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("http://www.edureka.co/");
driver.findElement(By.xpath("//button[text()='Sign Up']")).click();
// Create object of WebDriverWait class and it will wait max of 20 seconds.
WebDriverWait wait = new WebDriverWait(driver, 20);
// Here we will wait until element is not visible, if element is visible then it will return web element or else it will throw exception
WebElement element = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[text()='WebDriver']")));
boolean status = element.isDisplayed();
if (status) {
System.out.println("===== WebDriver is visible======");
} else {
System.out.println("===== WebDriver is not visible======");
}
}
}