Selenium geb StaleElementReferenceException

Selenium geb StaleElementReferenceException,selenium,automated-tests,geb,Selenium,Automated Tests,Geb,我刚刚开始将geb与webdriver一起用于自动化测试,当我在页面上定义内容时,每次调用内容定义时都应该查找页面元素 //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 moduleI

我刚刚开始将geb与webdriver一起用于自动化测试,当我在页面上定义内容时,每次调用内容定义时都应该查找页面元素

//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
因此,在这段代码中,我认为应该重复调用
$('.load')
,以便在模块的基本元素上下文中通过选择器在页面上查找元素。然而,在这一点上,我有时会遇到StaleElementReference异常。据我所知,元素不会从页面中删除,但即使删除了,也不会产生此异常,除非
$
正在后台进行一些缓存,但如果是这种情况,则会导致各种其他问题


有人能帮我理解这里发生了什么吗?为什么在查找元素时可以获取StaleElementReferenceException?指向相关文档或geb源代码的指针也会很有用。

事实证明,问题在于模块本身表示的元素的引用因修改而过时,而不是
.loading
元素。我怀疑异常源于该行,因为它试图在模块的基本元素中搜索.loading元素。解决方案是在检查模块内部元素的同时加载模块。在这种情况下,它看起来像这样:

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

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

//in a test on this page
waitFor { moduleItems(someIndex).itemLoaded }
感谢geb用户邮件列表中的Marcin为我指明了正确的方向