testing - 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
解决方案
推荐阅读
- python - 创建 Shopify Collect 时出错:{'base': ["can't be blank"]}
- javascript - 在 Google Apps 脚本中将 Date(JS) 对象转换为 TimeStamp(firestore)
- java - 具有原始类型的 JNI GetObjectClass
- reactjs - 样式选择下划线
- google-chrome - 如何使用 Python 在新标签页中的 Google Chrome 中打开 URL?
- javascript - AngularJs $q 承诺与 async/await 兼容吗?
- javascript - PrimeNG 9:以反应形式显示在 p-multiselect 中选择的值
- draftjs - Draft-js toJS 和 fromJS EditorState
- websphere - 错误:无法登录在 OCP 4.3 上安装 IBM Cloud Pak for Application 4.1
- deno - 我可以使用命令行交互工作吗?