I just want Selenium to do it for me
Well, you do have some options available if you just want Selenium to try to do it for you. Selenium has three built-in waiting mechanisms that you can configure universally by configuring the Timeouts()
object that is set on your driver object when you instantiate it. The available mechanisms are these:
- Page load timeout
- Script timeout
- Implicitly wait timeout
Let's have a look at them in some more detail.
Page load timeout
This defines the amount of time that Selenium will wait for a page to load. By default, it is set to 0 (which equates to an infinite time out). If you want to ensure that an error is thrown if your page takes longer than expected to load, you can modify this by using this line of code:
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
If your page does not load within 15 seconds, WebDriverException
will be thrown.
You should of course be aware that, while Selenium does its best to ensure that the page is loaded, you should...