java.util.NoSuchElementException解决办法

报错代码

public void switchToNewWindow(){
    //得到当前句柄
String currentWindow = driver.getWindowHandle();
    //得到所有窗口的句柄
    Set<String> handles = driver.getWindowHandles();
     
    //排除当前窗口的句柄,则剩下是新窗口
    Iterator<String> it = handles.iterator();
    while(it.hasNext()){
        if(currentWindow == it.next())  continue;
        driver.switchTo().window(it.next());      
    }
     
}

修改后的代码

    String currentWindow = driver.getWindowHandle();
          //得到所有窗口的句柄
          Set <String> handles = driver.getWindowHandles(); 
          //排除当前窗口的句柄,则剩下是新窗口
          Iterator<String> it = handles.iterator();
          while(it.hasNext()){
              String it1 = it.next();
              if(currentWindow == it1)  continue;
              driver.switchTo().window(it1);      
          } 

参考博客 http://www.cnblogs.com/joewu/p/3718721.html

posted on 2015-09-24 09:50  tsw123  阅读(262)  评论(0编辑  收藏  举报

导航