你可以做的是先檢查是否有對不
public boolean isAlertPresent() {
try{
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.alertIsPresent());
return true;
}
catch (NoAlertPresentException noAlert) {
return false;
}
catch (TimeoutException timeOutEx){
return false;
}
}
彈出存在,如果它存在,那麼你可以接受它像
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.accept();
OR
JavascriptExecutor爲你工作。請注意,您應該在點擊調用警報的事件之前執行它。
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");
注意: - 請勿在點擊調用警報確認框的事件後使用它。以上代碼默認情況下將確認框設置爲true表示如果調用該頁面上的所有確認框,則表示您接受/單擊確定。如果你想關閉提醒
希望它會幫助你:)
有沒有驗證彈出? –
像: - https://staging.carfax.si/ –
@ PapeK24我檢查了你喜歡的鏈接。這是一個身份驗證彈出,我想知道,你是否試圖關閉身份驗證彈出而不傳遞任何用戶名/密碼值? –