2016-08-19 154 views
1

我正在使用Java來編寫測試。我的Chrome瀏覽器版本是52.0,我的硒驅動程序是2.53。在我的目標網頁上有一個按鈕,點擊後會顯示警報。我總是習慣:無法處理警報消息

try{ wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click(); 
        Thread.sleep(1000); 
        wait.until(ExpectedConditions.alertIsPresent()); 
        driverChrome.switchTo().alert().accept(); 
    } 
    catch(Exception e){ 
    e.printStackTrace(); 
    } 

處理警報,但由於今天早上,當測試點擊按鈕上的警報,它拋出右後彈出,但隨後:

org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status 
from unexpected alert open 
(Session info: chrome=52.0.2743.116) 
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 33 milliseconds 

它不甚至到第二和第三線! 錯誤是由第一線

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click(); 

回答

1

我曾經碰到過同樣的事情在Chrome時正在點擊的按鈕是一個iframe內拋出。只需在Firefox中運行測試。請參閱登錄鉻bug跟蹤這2個問題 -

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1362

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1224

 try{ 
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click(); 

     } 
     catch(Exception e){ 
     e.printStackTrace(); 
     } 
    Thread.sleep(1000); 
         wait.until(ExpectedConditions.alertIsPresent()); 
         driverChrome.switchTo().alert().accept(); 
+0

但它昨天工作!發生了什麼 ?我們必須使用Chrome: –

+0

嘗試在按鈕單擊行處捕獲異常,它會拋出WebDriverException,然後檢查警報處理代碼是否正常工作,您也可以嘗試使用睡眠模式 – Grasshopper

+0

請查看編輯後的問題。它會在第一行拋出錯誤,但它不會; thread.sleep –