来回切换页面并关闭其他tab

Posted 在天成象

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了来回切换页面并关闭其他tab相关的知识,希望对你有一定的参考价值。

要下班了,就先把这个方法copy上来。反正自己能看懂。

public void checkSchemaDetail(String logext, String expectRes){
String currentWindow = driver.getWindowHandle();
schemaDetail.click();
Set<String> windowSet = driver.getWindowHandles();
for(String window : windowSet){
if(!window.equals(currentWindow)){
driver.switchTo().window(window);
logger.warn(logext+" the attached url of schemaDetail is "+driver.getCurrentUrl());
if(expectRes != null && !expectRes.equals("")){
WebElement schemeId = driver.findElement(By.name("id"));
WebElement schemeName = driver.findElement(By.name("name"));
String actualRes = schemeId.getAttribute("value")+" : "+schemeId.getAttribute("value");
if(expectRes.equals(actualRes))
logger.info("the schemeId and schemeName of jumped page is all right");
else
logger.warn("the schemeId and schemeName of jumped page expect: "+expectRes+", actual: "+actualRes);
}
driver.close(); //只会关掉当前tab,用qiut会关掉整个浏览器
}
}
driver.switchTo().window(currentWindow);
}

以上是关于来回切换页面并关闭其他tab的主要内容,如果未能解决你的问题,请参考以下文章

[Layui]主页tab选项卡操作(刷新页面,刷新选项卡,关闭,关闭其他,全部关闭)

[Layui]主页tab选项卡操作(刷新页面,刷新选项卡,关闭,关闭其他,全部关闭)

java+selenium——打开多个窗口,并切换窗口——方法一

程序员快捷键

如何在页面中关闭当前tab

windows 10常用快捷键举例