title: java.util.NoSuchElementException in iterator method
body: <p>I am relatively new to coding.</p>
  
  <p>Below is the code for my program which opens a windows(flipkart.com)> proceeds to the secondary window by clicking an icon inside the web-page. Now I want to generate the window handles for both first and second page but it gives me errors as given below</p>
  
  <p>Programs:</p>
  
  <pre><code>package MoinPrograms;
  
  import java.util.Iterator;
  import java.util.Set;
  import java.util.concurrent.TimeUnit;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  
  public class MouseOverActions {
  
      public static void main(String[] args) {
  
          WebDriver driver = new FirefoxDriver();
          driver.manage().window().maximize();
          driver.get("https://www.flipkart.com/");
          driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
          driver.findElement(By.xpath("// button [@class=\"_2AkmmA _29YdH8\"]")).click();
          driver.findElement(By.xpath("//p [@class=\"_1AuloC\"and text()= \"Mobiles &amp; Tablets\"]")).click();
          Set&lt;String&gt; FlipKart = driver.getWindowHandles();
          Iterator&lt;String&gt; k = FlipKart.iterator();
          String handle1 = k.next();
          String handle2 = k.next();
          System.out.println(handle1);
          System.out.println(handle2);
      }
  
  }
  </code></pre>
  
  <p>Errors :</p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException
      at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(Unknown Source)
      at java.base/java.util.LinkedHashMap$LinkedKeyIterator.next(Unknown Source)
      at MoinPrograms.MouseOverActions.main(MouseOverActions.java:24)
  </code></pre>