资源推荐:
视频资源: 软件测试相关系列视频
社区资源: 自动化测试交流群
public void testBaidu() throws Exception {
driver.get("http://www.baidu.com");
String parentID = driver.getWindowHandle(); //save current windowHandle
driver.findElement(By.linkText("新 闻")).click();
Set<String> allID = driver.getWindowHandles(); //save all opened windowHandle
if(allID.remove(parentID)){ //remove the first windowhandle
System.out.println("remove the first windowHandle success");
}
Iterator<String> iter = allID.iterator();
while(iter.hasNext()){
driver.switchTo().window(iter.next());//swith to the second handle
driver.getCurrentUrl();
}
driver.findElement(By.linkText("总政治部副主任吴昌德等6人晋升上将")).click();
Thread.sleep(5000);
System.out.println("it's over");
}