Waiting for WebElements to load

If you have a previous UI automation experience, I'm sure you would have come across a situation where your test script couldn't find an element on the web page because the web page was still loading. This could happen due to various reasons. One classic example is when the application server or web server is serving the page too slowly due to resource constraints; the other could be when you are accessing the page on a very slow network. The reason could be that the element on the web page is not loaded by the time your test script tries to find it. This is where you have to calculate and configure the average wait time for your test scripts to wait for WebElements to load on the web page.

WebDriver provides test-script developers with a very handy feature to manage wait time. Wait time is the time your driver will wait for the WebElement to load, before it gives up and throws NoSuchElementException. Remember, in Chapter 1, Introducing WebDriver and WebElements, we discussed the findElement(By by) method that throws a   NoSuchElementException when it cannot find the target WebElement.

There are two ways by which you can make the WebDriver wait for WebElement. They are Implicit Wait Time and Explicit Wait Time. Implicit timeouts are common to all the WebElements and have a global timeout period associated with them, but the explicit timeouts can be configured to individual WebElements. Let's discuss each of them here.

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

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