Understanding Webdriver Waits

It is very important for automated tests to be robust and reliable, so that the purpose of automated testing is full-filled. Tests need to be designed in such a way that they are able to handle tests in an effective manner and also take into account the various network or infrastructure constraints that may be present.

Yeah this happens with most of the websites today. Most of the websites today have some kinds of AJAX or JSON elements embedded in the UI. As such, at most times these webelements are slower to load. As such , it becomes important to handle such latency. Also, many times, due to peak traffic or network latency, our application may behave differently than it does at normal, optimal conditions. In these cases, we need to wait some particular time for the web elements to allow them to load properly and then use them in our tests.

 

Webdriver API provides us with two types to wait mechanisms to handle such conditions. We will discuss about these wait conditions here. These two types of waits are :

  • Implicit Wait

  • Explicit Wait

 

Let us discuss these in brief.

 

Implicit Wait

As the name suggests, implicit waits are a generic way of telling the test to wait for a certain amount of time to search for an element or to process a command, before an exception is raised. Implicit waits are implemented using the implictly_wait( ) method in many of the scripts that we have been through as of now.

 

Explicit Wait

As the name suggests, Explicit waits are helpful in situations when you can’t define your wait condition using the implicit waits. Explicit waits are a more preferred way of handling waits in most of the test, because it lets you set predefined conditions to handle a wait. Python provides the explicit waits using the expected_conditions class

 

Let is discuss this in a little more detail here.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.