TA的每日心情 | 奋斗 2018-8-27 15:56 |
---|
签到天数: 322 天 连续签到: 1 天 [LV.8]测试军长
|
// 根据Title切换新窗口
public boolean switchToWindow_Title(WebDriver driver, String windowTitle) {
boolean flag = false;
try {
String currentHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
for (String s : handles) {
if (s.equals(currentHandle))
continue;
else {
driver.switchTo().window(s);
if (driver.getTitle().contains(windowTitle)) {
flag = true;
System.out.println("Switch to Window: " + windowTitle
+ " successfully~~~!");
break;
} else
continue;
}
}
} catch (NoSuchWindowException e) {
System.out.println("Window: " + windowTitle + " cound not find!!!"
+ e.fillInStackTrace());
flag = false;
}
return flag;
} |
|