What are waits? And why do we need waits in Selenium?
Making an application grow might be one of the pain points for the industry. When it comes to QAing an application via automation, Selenium waits play a key role!
If there is a time lag, we can use these commands while executing our test script or doing any kind of dynamic testing.
While a user interacts with web elements, they might load at different time intervals causing some sort of delay.
So, understanding the selenium waits and sleep strategy is one of the essential components of forming an automation testing strategy using selenium.
Common Selenium wait exceptions
There are two most common exceptions while doing dynamic testing ; “ElementNotVisibleException” and “NoSuchElementException”
What happens without the selenium wait?
Without wait script throws above exceptions For example, consider a famous travel website – www.easemytrip.com
Often, elements are load with some kind of delay.
Types of wait :
1. Implicit wait
Implicit wait applies to the entire script.
This is the only type of wait that is applied to the entire script. Meaning, that you just need to write the implicit wait once and it will be applied to all the web elements which exists in the script.
To showcase this via example, I will be using the same script.
2. Explicit wait
Sometimes, the script needs some conditions to be met. Those include some instructions given to the driver before it throws any exception and meet the expected conditions.