如何区分弹出式窗口,警报窗口和新窗口?

问题描述:

如果一个新窗口打开,我们将如何确定新窗口是否为alert或popup或窗口?如何区分弹出式窗口,警报窗口和新窗口?

在执行任何操作之前,您需要将控件切换到弹出窗口。通过使用这个你可以解决你的问题。

Before opening the popup window get the handle of main window and save it. 

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 windows 

Iterator 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); 
    } 
}