Selenium webdriver Geb EmptyNavigator不存在
这里使用Geb 0.13.1。我并没有尝试将其与任何类型的测试框架集成(目前),只是尝试了解其DSL。我只想让Geb启动一个Firefox浏览器,将其指向谷歌主页,并在搜索地址中键入“gmail”(id为“Selenium webdriver Geb EmptyNavigator不存在,selenium-webdriver,groovy,geb,Selenium Webdriver,Groovy,Geb,这里使用Geb 0.13.1。我并没有尝试将其与任何类型的测试框架集成(目前),只是尝试了解其DSL。我只想让Geb启动一个Firefox浏览器,将其指向谷歌主页,并在搜索地址中键入“gmail”(id为“q”的HTML): 当我运行此程序时,Firefox会打开并转到Google,但在查找搜索(“q”元素)栏以设置以下值时,Firefox似乎会阻塞: Exception in thread "main" geb.error.RequiredPageContentNotPresent: The
q
”的HTML
):
当我运行此程序时,Firefox会打开并转到Google,但在查找搜索(“q
”元素)栏以设置以下值时,Firefox似乎会阻塞:
Exception in thread "main" geb.error.RequiredPageContentNotPresent: The required page
content 'sandbox.geb.GoogleHomepage -> search: geb.navigator.EmptyNavigator' is not
present
你知道这里发生了什么吗?我觉得你的谷歌主页有点傻。 如果您让它看起来更像这样,更好地遵循geb dsl会怎么样
class GoogleHomepage extends Page {
url = 'http://google.com'
static at = {
waitFor() {
title == 'Google'
content
}
}
static content = {
search(required: true) { $('input#lst-ib') }
}
}
您得到的是EmptyNavigator,因为您正在查找id为q$('input#q')的输入,请改为尝试$('input[name=q])。谢谢@zypherman(+1)-但即使进行了更改,也会出现相同的异常。上面的Deon似乎是正确的。如果你查看Google主页上的DOM,你会发现搜索输入没有q的id。id实际上是“lst ib”。如果您想使用name=q,请使用上面的选择器。否则,您可以使用$(“input#lst ib”)。我更新了上面的示例,以包含正确的id,并使at checker方法更好一些。告诉Geb等待页面加载和所有需要的元素出现是很重要的。否则,您将尝试与未完全呈现的dom交互。
class GoogleHomepage extends Page {
url = 'http://google.com'
static at = {
waitFor() {
title == 'Google'
content
}
}
static content = {
search(required: true) { $('input#lst-ib') }
}
}