How to check if a popup window is open or not using Selenium WebDriver in Java
If it's a native, browser alert (= a popup) you can do the following:
try{ driver.switchTo().alert(); // If it reaches here, it found a popup} catch(NoALertPresentException e){}
What it looks like you're actually dealing with is an iframe which you can do the following after getting the attribute value of the "iframe" attribute:
driver.switchTo.frame("ValueOfIframe");// Treat as normal webpage. Now in iframe scopedriver.switchTo.defaultContent(); // To return back to normal page scope
String mwh=driver.getWindowHandle();
Now try to open the popup window by performing some action:
driver.findElement(By.xpath("")).click();Set s=driver.getWindowHandles(); //this method will gives you the handles of all opened windowsIterator ite=s.iterator();while(ite.hasNext()){ String popupHandle=ite.next().toString(); if(!popupHandle.contains(mwh)) { driver.switchTo().window(popupHandle); /**/here you can perform operation in pop-up window** //After finished your operation in pop-up just select the main window again driver.switchTo().window(mwh); }}