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

时间:2021-05-12 19:15:10

要下班了,就先把这个方法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);
}