Groovy 如何使用geb自动单击确认弹出窗口?
我正试图通过使用Groovy、Maven、Geb和Spock自动化web应用程序的ui测试。我有一个页面,显示确认弹出窗口,在点击页面上的按钮后询问用户“你确定吗?-是-否”。我可以点击页面上的按钮,我还需要点击弹出窗口中的“是”按钮。当我检查Google Chrome上的“是”按钮时,它看起来是可用的,因此我在页面上使用了它的名称,如下所示: MyPage.groovyGroovy 如何使用geb自动单击确认弹出窗口?,groovy,spock,geb,ui-testing,Groovy,Spock,Geb,Ui Testing,我正试图通过使用Groovy、Maven、Geb和Spock自动化web应用程序的ui测试。我有一个页面,显示确认弹出窗口,在点击页面上的按钮后询问用户“你确定吗?-是-否”。我可以点击页面上的按钮,我还需要点击弹出窗口中的“是”按钮。当我检查Google Chrome上的“是”按钮时,它看起来是可用的,因此我在页面上使用了它的名称,如下所示: MyPage.groovy import geb.Page class page extends Page{ static url = "my
import geb.Page
class page extends Page{
static url = "myPage"
static at = { waitFor { title == "My Page" }}
static content =
{
confirmBtn {$("input[value*='Confirm']")}
yesBtn {$("input[value*='Yes']")}
}
}
import geb.spock.GebSpec
import MyPage
class MySpec extends GebSpec{
def "Confirm"(){
given:
def page = to MyPage
when:
go MyPage
page.confirmBtn.click()
yesBtn.click()
then:
...
}
}
这就是我试图单击“是”的内容:
MySpec.groovy
import geb.Page
class page extends Page{
static url = "myPage"
static at = { waitFor { title == "My Page" }}
static content =
{
confirmBtn {$("input[value*='Confirm']")}
yesBtn {$("input[value*='Yes']")}
}
}
import geb.spock.GebSpec
import MyPage
class MySpec extends GebSpec{
def "Confirm"(){
given:
def page = to MyPage
when:
go MyPage
page.confirmBtn.click()
yesBtn.click()
then:
...
}
}
因此,它给了我以下例外情况:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
我如何点击“是”按钮,你有什么建议吗
编辑:
我通过在单击按钮之前添加以下行来调试代码:
waitFor { yesBtn.isEnabled() }
println "isDisplayed: " + yesBtn.isDisplayed()
println "isEnabled: " + yesBtn.isEnabled()
但无论我是否等待按钮启用或显示,它都会打印:
isDisplayed: false
isEnabled: true
阅读之后,我想到dom需要以某种方式刷新。因为当页面第一次加载时按钮将不在那里,通过传递
required:false
如下:
yesBtn(required:false) { $("input[value*='Yes']") }
你试过
yesBtn(必选:false){$([input[value*='Yes'])}
?@tim_yates在你的评论后,我试过了,但在MySpec中没有效果。groovy替换:yesBtn.click()for:waitFor{yesBtn.click()}谢谢你的建议,但效果不好@jripoll@tim_yates很抱歉,它起作用了。它不起作用,因为有几个元素具有相同的值,我第一眼就不知道。如果你能添加你的评论作为答案,那就太好了。