Explicit wait time

Implicit timeout is generic to all the WebElements of a web page. But, if you have one specific WebElement in your application, where you want to wait for a very long time, this approach may not work. Setting the implicit wait time to the value of this very long time period will delay your entire test suite execution. So, you have to make an exception for only a particular case, such as this WebElement. To handle such scenarios, WebDriver has an explicit wait time for a WebElement.

So, let's see how you can wait for a particular WebElement using WebDriver, with the following code:

WebElement searchBox = (new WebDriverWait(driver, 20))
.until((ExpectedCondition<WebElement>) d -> d.findElement(By.name("q")));

The highlighted code is where we have created a conditional wait for a particular WebElement. The ExpectedCondition interface can be used to apply the conditional wait to a WebElement. Here, WebDriver will wait for a maximum of 20 seconds for this particular WebElement. The implicit timeout doesn't get applied for this WebElement. If the WebElement doesn't load within the 20 seconds maximum wait time, as we know, the driver throws a NoSuchElementException. Thus, you can override the implicit wait time exclusively for the WebElements you think will take more time, by using this handy explicit wait time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.46