Misuse of waitForPageToLoad() of Selenium

By xngo on February 28, 2019

The common mistake that people usually do is to use waitForPageToLoad() function to wait for what appears to be a webpage being loaded. But, in fact, it is Ajax or JavaScript that is doing some changes to a portion of the webpage. As a result, the waitForPageToLoad() function will always time out because it is expecting for the whole webpage to load that never happened.

So, the next time that you get a time out on waitForPageToLoad() function even though that you swear you have allocated more than enough time to it, then you are not using waitForPageToLoad() function correctly. A simple trick to know is to replace the waitForPageToLoad() function with a pause. If Selenium is able to execute the next instruction, then you shouldn't use the waitForPageToLoad() function. Perhaps, you should consider to write a new function to wait for what you expected.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.