我刚刚开始使用带有webdriver的geb进行自动化测试。As I understand it,当我在页面上定义内容时,每次调用内容定义时都应该查找页面元素。
//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因此,在这段代码中,我认为应该重复调用$('.loading'),以便在模块的基本元素的上下文中通过选择器查找页面上的元素。然而,在这一点上,我有时会得到一个StaleElementReference异常。据我所知,该元素不会从页面中删除,但即使从页面中删除,也不会产生此异常,除非$在幕后进行一些缓存,但如果是这样的话,将会导致各种其他问题。
有人能帮我弄明白这里发生了什么吗?为什么可以在查找元素时获得StaleElementReferenceException?指向相关文档或geb源代码的指针也会很有用。
发布于 2012-09-01 11:34:06
事实证明,问题在于对模块本身所表示的元素的引用已通过修改而变得陈旧,而不是.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为我指明了正确的方向。
https://stackoverflow.com/questions/12222081
复制相似问题