首页 > 解决方案 > Geb Groovy 测试:如何在不关闭浏览器的情况下关闭当前选项卡?

问题描述

我试过了:

$('body') << Keys.chord(Keys.CONTROL, "w") -
driver.close()
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"w")

这是测试的代码:

    def "scrape"() {
    when:
    ScrapeTestPage page = to ScrapeTestPage

    then:

    $("input", name: "search").value("test")
    $("button", type: "submit").click()
    
    $('td a', 0).click() //this opens a new tab

    DetailsPage page1 = to DetailsPage

    println "test"
    //now I'd like to close that tab without closing the first one


}

我尝试将新选项卡包装在 withNewWindow 中,但它会引发错误:

withNewWindow({$('td a', 0).click()}){} | org.openqa.selenium.InvalidArgumentException:预期“句柄”是一个字符串,得到 [object Undefined] undefined

标签: testinggroovygeb

解决方案


推荐阅读