Search code examples
selenium-webdrivergeb

Does Geb cache Page Objects


I'm trying to run a test where I have a list of ids to search in a web application and check if a property is set for each one. I modeled the search result as a Page, but every time I load a new search result the first result seems to be cached and I eventually get a stale element reference exception. How does one instantiate a new SearchResult page object for each searched id?


Solution

  • There is no concept of caching for pages in Geb. Page content elements can be cached though but they are not cached by default. You might be still getting StaleElementReferenceException even it things are not cached, for example when interacting with DOM elements which are removed while doing so and I suspect that this is what's happening in your case.

    If your page is dynamic, i.e. the DOM is modified in an asynchronous way after an action is performed on the page then you should ensure to wait for the page to stabilise before interacting with the content. And there is no need to use WebDriver APIs directly to achieve it.

    I would be able to give you better guidance if you shared code of your page class and the stacktrace you're getting.