What lies in Selenium waits?

Reading Time: 2 minutes

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.

Ajax and JavaScript used by the developers might be one of the reasons for this!

When a page refresh is done in a heavy-dynamic web page (filled with javascript), elements don’t get a load at once like calander elements; they get added over the time as they are received from network calls. Hence, when our script tries to find an element that is not loaded, it immediately fails even if there is a difference in milliseconds.

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.

References :

Written by 

Nearly 3 years of experience in automation testing, I call myself an automation enthusiast. I can create, execute automated test scripts using framework guidelines and best practices to ensure wider and efficient end-to-end automation coverage. Simultaneous experience in Defect tracking and bug reporting through JIRA