如何区分硒中的弹出窗口,警报和新窗口?

时间:2017-09-01 09:29:12

标签: selenium

如果新窗口打开,我们如何确定新窗口是警报还是弹出窗口还是窗口?

1 个答案:

答案 0 :(得分:0)

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

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