geb StaleElementReferenceException

Posted by Brian Mortenson on Stack Overflow See other posts from Stack Overflow or by Brian Mortenson
Published on 2012-08-31T20:28:33Z Indexed on 2012/09/01 3:38 UTC
Read the original article Hit count: 130

Filed under:
|
|

I have just started using geb with webdriver for automating testing. As I understand it, when I define content on a page, the page element should be looked up each time I invoke a content definition.

//In the content block of SomeModule, which is part of a moduleList on the page:
itemLoaded {
    waitFor{ !loading.displayed }
}
loading { $('.loading') }


//in the page definition
moduleItems {index -> moduleList SomeModule, $("#module-list > .item"), index}

//in a test on this page
def item = moduleItems(someIndex)
assert item.itemLoaded

So in this code, I think $('.loading') should be called repeatedly, to find the element on the page by its selector, within the context of the module's base element. Yet I sometimes get a StaleElementReference exception at this point. As far as I can tell, the element does not get removed from the page, but even if it does, that should not produce this exception unless $ is doing some caching behind the scenes, but if that were the case it would cause all sorts of other problems.

Can someone help me understand what's happening here? Why is it possible to get a StaleElementReferenceException while looking up an element? A pointer to relevant documentation or geb source code would be useful as well.

© Stack Overflow or respective owner

Related posts about selenium

Related posts about automated-tests