根据“Geb 之书”,我开始绘制我们门户网站的网页。我更喜欢使用在静态内容闭包块中定义的变量,然后在页面方法中访问它们:
static content = {
buttonSend { $("input", type: "submit", nicetitle: "Senden") }
}
def sendLetter() {
waitFor { buttonSend.isDisplayed() }
buttonSend.click()
}
不幸的是,有时我会收到 Geb 等待超时异常(60 秒后),或者更糟糕的是,我会收到众所周知的“StaleElementReferenceException”。
使用“isEnabled”而不是“isDisplayed”时,我可以避免等待超时,但对于“StaleElementReferenceException”,我只能应用以下解决方案:
def sendLetter() {
waitFor { buttonSend.isEnabled() }
try {
buttonSend.click()
} catch (StaleElementReferenceException e) {
log.info(e.getMessage())
buttonSend.click()
}
}
我想,这个解决方案不是很好,但我无法应用另一篇文章中描述的显式等待。因此,我有一些一般性问题:
- 当页面是动态的时,我应该避免使用静态内容定义吗?
- Geb 在什么时间或事件刷新其 DOM?如何触发 DOM 刷新?
- 为什么在使用 CSS 选择器时仍然会收到“StaleElementReferenceException”?
我将不胜感激每一个有助于理解或解决这个问题的提示。最好有一个简单的代码示例,因为我还是个初学者。谢谢!