I am clicking on a link, which results in new tab. I want to move to that tab, close that tab, and then again switch back to Parent window.
I have written following code, its showing error, Actually in my code, control is not moving to child window. Please see following code, and help me:
WebDriver driver;
System.setProperty("Webdriver.chrome.driver", "chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open");
String parent_window = driver.getWindowHandle();
driver.switchTo().frame("iframeResult");
driver.findElement(By.xpath("//button[contains(text(),'Try it')]")).click();
Thread.sleep(4000);
String child_window = driver.getWindowHandle();
System.out.println(parent_window);
System.out.println(child_window);