I am relatively new to coding.
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
Programs:
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 & Tablets\"]")).click();
Set<String> FlipKart = driver.getWindowHandles();
Iterator<String> k = FlipKart.iterator();
String handle1 = k.next();
String handle2 = k.next();
System.out.println(handle1);
System.out.println(handle2);
}
}
Errors :
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)