Switch to pop up window using Selenium Switch to pop up window using Selenium selenium selenium

Switch to pop up window using Selenium


public String determineIfCorrectUrlOnPopUp() {clickOnEmailThisSeller();// Below Line in your code will switch to  the current window  by using for each loopfor (String currentWindow: driver.getWindowHandles())       driver.switchTo().window(currentWindow);{   //Now you are in Popup window and you can get the pop-up window URL here    System.out.println(driver.getCurrentUrl());    driver.close();  }System.out.println(driver.getCurrentUrl()); // This will return Parent window URLreturn driver.getCurrentUrl();}


Have you tried

driver.switchTo().window(handle).getCurrentUrl();

I haven't done a lot of this but I did write a little function that closes popup windows and I used

driver.switchTo().window(handle).close();

to close the popup.