I using Selenium WebDriver to test a website. I have PageObjects to represent the LoginPage
, the HomePage
and the ManagementPage
. My test first logs in, which returns a HomePage
, then clicks a button that returns a ManagementPage
. Then it checks a bunch of stuff, clicks a link back to the HomePage
, then clicks a logout link.
This all works fine with Chrome, without using a pageLoadTimeout
at all. However, in Firefox I get a NoSuchElementException
on when trying to click the logout link. I'm assuming this is because the page hasn't loaded fully when trying to click the logout button. So I put a driver.manage().timeouts().pageLoadTimeout(5000, TimeUnit.MILLISECONDS)
at the start of my test, right after I create the driver. I still get the same error. Changing the timeout to be 5 milliseconds
proves that the timeout is working because the page doesn't load and a TimeOutException
is thrown.
If I move the driver.manage().timeouts().pageLoadTimeout(5000, TimeUnit.MILLISECONDS)
to the constructor of the HomePage
then it all works fine though. So I can solve my problem by having the timeout being set for every PageObject.
I would like to be able to only set this once for each driver, which is what I gather it is meant to do from this question. But this question says that the pageLoadTimeout does not work for clicking on links, which confuses me because I does work for me, but only if I set it for each PageObject.
Is there something else I have to do? Or does the timeout get reset when the driver is passed to a PageObject? I can't see how that would be happening as all I do in the constructor is:
this.driver = driver;