How do we know that the page that we are interested in has loaded and is ready for us to start running our scripts against?
It sounds like a simple question, however, it is one of the things that always catches people out. If you are ever asked why a script doesn't work when the code seems sensible, your usual reply should probably be: it's a wait problem!
Wait problems are probably the most common errors in Selenium scripts. Shockingly, most of the time, people don't even know that they have them. JavaScript-heavy sites are especially prone to wait problems, but you can run into them with sites that don't use much JavaScript as well.
Why are wait problems so prevalent? It's largely due to people not thinking about the consequences of external variables when they write their scripts.
Let's take a made-up scenario. We have a page that waits until it is loaded to make an AJAX request to a server. This page is not ready to be used until the AJAX request is complete, but...