Explicit Wait is 1 of 5 Selenium Wait Methods. Unlike Implicit Wait, Explicit is used on 1 WebElement at a time unlike Implicit Wait. Explicit Wait is dynamic so it will wait for that 1 element or throw an exception. An exception is thrown if the element is not found within a specified time. In 6 minutes, this video demonstrates how to implement Explicit Wait using test application ‘The Internet’. https://the-internet.herokuapp.com/
Here’s a list of the other 4 Selenium Wait Methods:
1. Page Load Timeout - https://tinyurl.com/PageLoadTimeOut-W...
2. Implicit Wait - https://tinyurl.com/Video-Implicit-Wa...
3. Fluent Wait
4. Set Script Timeout
► Link to download the Transcript, Presentation, and Code =
https://www.rexjones2.com/selenium-wa...
► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books
► Increase Video Quality: Settings - Quality - Select HD
► CC Font Size: Settings - Subtitles/CC - Options - Font Size
► Turn CC On or Off: Click CC
► Transcript
Next is Explicit Wait. This is the same Test Script from Implicit Wait. Where we load the page, click the Dynamic Loading hyperlink, click Example 2, then click the Start button. Followed by finding Hello World, getting the text of Hello World, and printing Hello World. I’m going to run this Test Script again. It’s going to fail because of this dynamic Hello World element. Fail
Explicit Wait is used on 1 WebElement at a time. For that 1 element which is Hello World, execution will pause until time has expired or an expected condition is met using the WebDriverWait class.
Let’s start by writing WebDriverWait and wait as the object reference = new WebDriverWait() pass in driver and TimeOutInSeconds as 5 for the parameters. 5 represents the maximum number of seconds Selenium will wait for an element before throwing an exception.
Here’s the power of Explicit Wait. After clicking the Start button, we write wait dot until ExpectedConditions with an s dot. So far, we are going to wait until an expected condition is met. There’s many Expected Conditions. Our goal is to check if Hello World is present. We can select visibilityOfElementLocated which is an expectation for checking that an element is present. Locator will be By.xpath(). Go back to the application, Inspect Hello World, Copy xpath, Paste xpath.
Let’s run. Hello World is printed to the Console. All of the ExpectedConditions are examples that assist us with writing our own customized Explicit Wait statements.
Let’s breakdown Explicit Wait.
With the first line, we have the WebDriverWait class which has a Constructor of WebDriverWait and 2 parameters. driver and 5. Let’s view JavaDocs for the WebDriverWait class. It has 3 Constructors. 1, 2, and 3. We used the 2nd Constructor which ignore instances of NotFoundException.
NotFoundException is an exception that is thrown when an element is not found. We see both parameters: driver and timeOutInSeconds. driver is the WebDriver instance while timeOutInSeconds is the timeout in seconds when an expectation is called.
The next line is wait until ExpectedConditions. wait is the object reference of the WebDriverWait class. until is a method that repeats until one of the following occurs.
Number (1) the function returns neither null nor false.
Number (2) the function throws an unignored exception.
Number (3) the timeout expires.
Number (4) the current thread is interrupted.
Since Hello World was returned, Number(1) applies to our Test Script because Hello World is not null nor false. ExpectedConditions is a class that has so many methods. However, we used visibilityofElementLocated and the By locator was xpath. That’s it for Explicit Wait.
#SeleniumTraining #SeleniumAutomation #BeginnerSeleniumTutorials #SeleniumWebDriver
Watch video ✔ Benefits of Explicit Wait (A online, duration hours minute second in high quality that is uploaded to the channel Rex Jones II 24 January 2019. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 682 times and liked it 11 visitors.