本文共 692 字,大约阅读时间需要 2 分钟。
视频资源:
社区资源:
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"); }转载地址:http://ojrub.baihongyu.com/