An Implicit Wait Method is used to implement a default waiting time for each Test Step within the entire Test Script. While waiting, WebDriver continues polling the Document Object Model (DOM) for the WebElement. If the WebElement is placed before the default time then the next Test Step is executed. However, if the WebElement isn’t located within the specified time then an exception shows up. The below-given screenshots display a description and syntax for Implicit Wait.
Screenshot 01: Above screenshot shows the Implicit Wait Syntax and Description
Screenshot 02: Above screenshot shows the Implicit Wait 5 Seconds
Implicit wait accepts the below given 2 parameters:
- time – accepts the time as an integer value
- unit – accepts the time measurement in terms of SECONDS, NANOSECONDS, MINUTES, MILLISECONDS, MICROSECONDS, HOURS, and DAYS
Note: Usually, an Implicit Wait Method is provided before loading the web page within the setUp() method
Explicit Wait Methods are used to interrupt execution until time has elapsed or an expected condition is met. That condition must be satisfied before moving to the next Test Step. Selenium WebDrvier offers a WebDriverWait class and an ExpectedConditions class to assist Explicit Wait. It’s important to know that Explicit Waits are limited to a specific WebElement.
The WebDriverWait class creates an object reference and uses an instance of WebDriver. Also, a maximum number of seconds is added for execution inactivity. If the WebElement isn’t found then an exception is thrown. The below-given screenshot shows a description and syntax for WebDriverWait:
Screenshot 03: Above screenshot shows the WebDriverWait Syntax and Description
Screenshot 04: Above screenshot shows the WebDriverWait- TimeOut In 5 seconds
In the above example, an object reference of wait is created for WebDriverWait while the driver is the reference object for WebDriver. A maximum of 5 seconds is provided to locate the WebElement. Afterward, an automation engineer has to inform WebDriver to wait until an expected condition is met. The ExpectedConditons class supplies many methods for using these scenarios that may occur before executing the next Test Step. Here’s a screenshot that displays a few ExpectedConditions methods.
Screenshot 05: Above screenshot shows the Methods via ExpectedConditions Class
Screenshot 06: Above screenshot shows the ExpectedConditions Example
The ExpectedConditions class is accessed after writing the WebDriverWait reference “wait, dot operator, then until() method. Subsequently, many methods are available when writing dot after ExpectedConditions. The above statements look ahead to whichever happens first: wait for seconds or until the element is clickable. In alphabetical order, below given is a list of additional methods that are not shown in the screenshot
The following is a table summarizing Implicit and Explicit Wait:
People having good knowledge of Financial accounting can get an Accounting Certification Exams from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.