What is Implicit wait in Selenium WebDriver?
It means that we can tell Selenium that we would like it to wait for a certain amount of time before throwing an exception (when it cannot find the element on the page).
For example:
driver.manage().timeouts().pageLoadTimeout(50,TimeUnit.SECONDS);
Above statement will set the navigation timeout as 50. This means that selenium script will wait for maximum 50 seconds for page to load. If page does not load within 50 seconds, it will throw an exception.
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Logic: – Selenium checks the control in first go, in case it is not able to find the control it will wait for the given implicit time, and then try again, after the end of the wait time to look for the control before throwing an exception. By default, its value is 0.
Limitation: – implicit wait will be applied to all the elements of the test case by default.
Key Notes
- Implicit wait is a single line of a code and can be declared in the setup method of the test script.
- When compared to Explicit wait, Implicit wait is transparent and uncomplicated. The syntax and approach is simpler than explicit wait.
- Implicit wait will not work all the commands/statements in the application. It will work only for “FindElement” and “FindElements” statements
Example for Implicit Wait
WebDriver driver = new FirefoxDiriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(“http://www.google.com”);
Refer below video –
Refer below links to know more about Explicit wait and Fluent wait –
What is Explicit wait? How to Achieve Explicit wait in Selenium?
What is Fluent wait? How to Achieve Fluent wait inSelenium?
Which is the best wait in selenium WebDriver?
Hope this Helps !!!!!