In the Previous Post, we have seen a behavior of Thread.sleep() wait in Selenium WebDriver and its disadvantages. I would recommend you to go through with that tutorial first. Click Here.
After reading the Previous Post, now we are clear that Wait concept is actually required in WebDriver Scripts to save them from fail due to some common application issues like Network Delays, Element loading, AJAX loading etc.
Implicit Wait tells WebDriver to poll the DOM for certain amount of time when trying to find an element or elements, if they are not immediately present on a webpage and when the element is not present even after implicit wait expires then WebDriver will throw NoSuchElementException.
So basically, It actually tells selenium to wait for specific amount of time before throwing NoSuchElementException.
Implicit Wait is basically a dynamic wait as it actually speed up your script execution, if you compare it with a static wait : Thread.sleep()
Let take an example, if implicit wait of 30 seconds in applied in a script and script finds an element in 5 seconds then the script won’t wait for another 25 seconds. Means, it moves ahead immediately as soon as it finds an element. And if element is not available in 30 seconds then WebDriver will throw an exception.
Implicit Wait can be set at the time of driver initialization. Once set, it will retain till the driver session exist. Mean to say, after setting an implicit wait, it will be applied on all elements of your test script until the driver session is ended using close() or quit() command.
In the above script, we have set an implicit wait of 30 seconds. It means if elements is not located on web page within 30 seconds then WebDriver will thrown an Exception.
When you run above, it will execute successfully as we have applied an implicit wait of 30 seconds. If you won’t apply it in above code, it will fail right after typing the Search Keyword because Suggestions will take some time to load. This issue can be handled by setting up an implicit wait in your script.
If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.