I recently had an excellent conversation with my bud Titus Fortner and realized that it’s actually pointless to check whether a page has loaded. Since all automated browsers tests aim to mimic user behavior, at some point we will be making a UI interaction. At this point, the UI interaction can tell us if something went wrong. Doing any page rendering validation before hand is actually redundant and a waste of time.

Let’s take a look at how I used to write my UI automation. I would start with a simple test and then expand to a more complicated one. Something like this.

So what happens when the first test fails?

I get the following exception

OpenQA.Selenium.WebDriverTimeoutException : Timed out after 5 seconds
      ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"class name","selector":"btn_action"}

What happens when the 2nd test fails?

I get the following exception

    OpenQA.Selenium.WebDriverTimeoutException : Timed out after 5 seconds
      ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"id","selector":"user-name"}

What’s the difference?

They’re the same exact exception!

The only difference is the element that wasn’t located. But that doesn’t matter because the end result is the same.

When a page doesn’t render, what does that mean?

First, it can mean that your server is down. In which case, driver.get("www.url.com") will fail for both scenarios.

Second, it can mean that the page didn’t render because of an HTML, CSS, JS issue. So, when we try to interact with any element on that page, we will get a NoSuchElementException. Doesn’t matter which element because the root cause of the problem is exactly the same.

Conclusion

So, as you can see, checking that the page has loaded is actually a pointless activity and a pointless test. The action that we take immediately after the page load will reveal if the page has rendered successfully.

Let me know if you agree that it’s unnecessary to check for a page load.

By the way, I have a post on the Automation Best Practices and Anti-Patterns if you want to learn more such practices to drastically enhance your test automation.