Waits in Selenium

Posted By : Sulabh Kumar | 29-May-2020

waits in selenium

When applying a tool to automate the testing of an online application, at times we tend to write code for a script that interacts with the appliance as a user would. An example would be accessing the controls on the screen, like typewriting in input fields, clicking on buttons, and so on.


Let’s suppose we've got an online application that contains many pages with many inputs, and a submit button. Our script feeds some information within the input fields, and so clicks on the submit button. Then, the following screen is loaded, on that, many alternative input fields are fed with input. If we do a manual test after clicking on the Submit button, we'll simply sit up for the following page to load, and enter info within the new fields. Being a Manual tester, it's simple. But how can we deal with such problems in automation testing? Well, we have some concepts of Waits to overcome these problems.


Thus, to tell the script by how much time we have to wait to enter data in the fields, we use Waits concepts. In Selenium there are mainly and widely used two forms of waits:


1. Implicit Wait

2. Explicit Wait


The implicit waits are used at the beginning of the script, once making the web driver instance. Let's say, for example, that every time we wish to get access to a particular field on the webpage, we must always sit up for some N milliseconds for the field to appear on the Web page. Thus to overcome such an issue, we apply implicit wait for N number of seconds so that the field appears on the webpage and the script continues to automate without throwing any error. The value of N is going to be valid for the total script until modified. Below is the basic Syntax for Implicit wait-




The explicit waits specify at that purpose precisely, and solely at that time, what quantity time we must always wait, and for what condition. The explicit wait is applicable only for certain elements.


Basic Syntax of Explicit wait is-

WebElement waitforemelent =wait.untill(ExpectedConditions.visiblityofElementLocated(By.xpath("xpath”)));


In conclusion, the waits in any automation tool are used to get all the required fields and pages that take some time to load and appear completely on the webpage, or for a few alternative conditions to become true, and provides the script some time before throwing the error. Thus the script gets synchronized with the web application to be tested.


As an ERP development company, at Oodles, we analyze your business criteria and goals and provide development tools, to automate, streamline, and accelerate operations. Our software tool kit comprises software like Selenium for automation. We use an extensive technology stack to ensure the smooth running of your business processes. Augment your business with automation. Contact our experts now!


Please remove URL from text

Comment is required

Sending message..
Connect with us