我正在使用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();
但它昨天工作!發生了什麼 ?我們必須使用Chrome: –
嘗試在按鈕單擊行處捕獲異常,它會拋出WebDriverException,然後檢查警報處理代碼是否正常工作,您也可以嘗試使用睡眠模式 – Grasshopper
請查看編輯後的問題。它會在第一行拋出錯誤,但它不會; thread.sleep –