Click on the button below. The paragraph field will tell you when 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 seconds have passed.
0
package com.wait.type;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class ImplicitWaitDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=null;
String browserName = "chrome";
if(browserName.equalsIgnoreCase("ie")){
driver = new InternetExplorerDriver();
}else if(browserName.equalsIgnoreCase("chrome")){
driver = new ChromeDriver();
}else if(browserName.equalsIgnoreCase("ff")){
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(11, TimeUnit.SECONDS);
Thread.sleep(3000);
driver.findElement(By.xpath("//button[text()='Display Time in Seconds']")).click();
//Script will wait atmost 11 seconds to perform this operation
//after 11 seconds it will failed and throw org.openqa.selenium.NoSuchElementException
String value = driver.findElement(By.xpath("//*[text()='10']")).getText();
if(value.equalsIgnoreCase("10")){
System.out.println("Test is passed");
}else{
System.out.println("Test is failed");
}
driver.close();
}
}
No comments:
Post a Comment