-2
如果一個新窗口打開,我們將如何確定新窗口是否爲alert或popup或窗口?如何區分彈出式窗口,警報窗口和新窗口?
如果一個新窗口打開,我們將如何確定新窗口是否爲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);
}
}