2017-09-01 73 views

回答

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