Waiting for elements
Before acting on an element, you need to make sure of two things: first, that the element is there, it exists in the DOM; and second, you can act on that element. In other words, it's visible to the user. Let's see how we can wait for our element to be ready.
You should wait for a selector after some kind of network call. You goto
a page, wait for a selector, and then you act. You click on a button, wait for a selector, and then you act.
In some cases, the selector you need to wait for is easy to find. On our login page, we need to wait for the user name input. In other cases, such as our home page, we would need to wait for the div
element containing all the products. It's just a little bit more complicated but still straightforward.
But what if we want to test Mango's newsletter popup? Maybe the pop-up HTML is on the page, but it's not visible. Here's where I start to consider waiting as a kind of art. It's not just...