Site icon

Implicit Wait in Selenium WebDriver – Java (Synchronization)

 Must Read: Handle ElementNotVisibleException in Selenium Webdriver

                     Explicit Wait in Selenium WebDriver

Syntax:

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

Implicit wait method accepts two  parameters :

Code for implicit wait:

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ImplicitWaitTest {

	protected WebDriver driver;

	@Test
	public void implicitWaitTest () throws InterruptedException {
		System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe");
		driver = new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
		// navigate to web site
		driver.get("https://makeinjava.com");
		// maximize the browser window
		driver.manage().window().maximize();
		// prints the title of web page
		System.out.println(driver.getTitle());
		driver.close();
	}
}

Exit mobile version