你可以做的是先检查是否有对不
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我检查了你喜欢的链接。这是一个身份验证弹出,我想知道,你是否试图关闭身份验证弹出而不传递任何用户名/密码值? –