首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >geb StaleElementReferenceException

geb StaleElementReferenceException
EN

Stack Overflow用户
提问于 2012-09-01 04:28:33
回答 1查看 1.8K关注 0票数 2

我刚刚开始使用带有webdriver的geb进行自动化测试。As I understand it,当我在页面上定义内容时,每次调用内容定义时都应该查找页面元素。

代码语言:javascript
复制
//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源代码的指针也会很有用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-01 11:34:06

事实证明,问题在于对模块本身所表示的元素的引用已通过修改而变得陈旧,而不是.loading元素。我怀疑异常来自该行,因为它试图在模块的基本元素中搜索以查找.loading元素。解决方案是在加载模块的同时检查其中的元素。在本例中,它看起来像这样:

代码语言:javascript
复制
//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为我指明了正确的方向。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12222081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档