2016-08-17 84 views
1

打開彈出後,請找到下面的代碼:代碼是沒有得到執行硒

d.findElement(By.id("txtUserName")).clear(); 
d.findElement(By.id("txtUserName")).sendKeys("[email protected]"); 
Thread.sleep(2000); 
d.findElement(By.name("txtTempBox")).clear(); 
Thread.sleep(2000); 
d.findElement(By.id("txtPassword")).sendKeys("password"); 
d.findElement(By.id("btnsubmit")).click(); 


Thread.sleep(2000); 
d.findElement(By.id("ctl00_ContentPlaceHolder1_rdoAdmin")).click(); 
Thread.sleep(2000); 
d.findElement(By.id("ctl00_ContentPlaceHolder1_lnkContinue")).click(); 
Thread.sleep(5000); 


//GC Inbox 

String s1 = "CHR-665";//d.findElement(By.id("ctl00_ContentPlaceHolder1_lblrequestidtext")).getText(); //For taking Request Id 
String tem[] = s1.split("-"); 
d.findElement(By.id("ctl00_ContentPlaceHolder1_ctlCommonInbox_txtGrantID")).sendKeys(tem[1]); 
d.findElement(By.id("ctl00_ContentPlaceHolder1_ctlCommonInbox_lnkSearch")).click(); 
Thread.sleep(5000); 
d.findElement(By.id("ctl00_ContentPlaceHolder1_ctlCommonInbox_grdAdminGrantCHR_ctl00_ctl04_btnAction")).click(); 
Thread.sleep(8000); 
d.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_lnkReleasePayment']")).click(); 

這將打開彈出窗口的最後一行後,代碼是沒有得到執行,以處理這種開彈出。 請找過這是我處理的彈出下面的代碼:

String MainWindow=d.getWindowHandle();  
Set<String> set=d.getWindowHandles();  
Iterator<String> it=set.iterator();  

while(it.hasNext())   
{  
    System.out.println("Inside While"); 
    String ChildWindow=it.next();  

    if(!MainWindow.equalsIgnoreCase(ChildWindow))   
    {    
      d.switchTo().window(ChildWindow);  


      d.close();  
    }  
} 
System.out.println("Outside While"); 
    d.switchTo().window(MainWindow); 

請讓我知道如何在彈出窗口被打開,因爲當我關閉彈出式手動然後執行彈出處理代碼只有此Pop-up處理代碼不在Pop-up打開時執行。

如果問題沒有提供令人滿意的信息,請讓我知道。

感謝

+0

您可以張貼在彈出的形象呢?你確定彈出窗口不是基於Windows的嗎? – ChanChow

+0

@ChanChow:是的,我確定它不是基於Windows的,因爲URL存在於Popup中。通過我無法在此處發佈圖片的方式,請讓我知道如何在此處發佈,如果您想查看彈出圖像。謝謝。 –

回答

0

嘗試使用Alert類或鏈接PopupWindowFinder代碼是基於C#,我希望你可以將其轉換爲所需的語言輕鬆 popup's in selenium webdrivers

+0

感謝您的答覆。我在下面的代碼中找到了解決方案.click():((JavascriptExecutor)driver).executeScript(「window.showModalDialog = window.open;」);這將調用window.open而不是window.showModalDialog。 –