好吧Raza,如果你的目的是檢查一個警報,並接受它,如果它存在(正如你所提到的,有些頁面顯示你警報和一些沒有);嘗試使用下面的方法看看是否能解決你的問題:
public boolean isAlertPresent() throws InterruptedException {
try {
for(int i=1; i<3; i++){
TimeUnit.SECONDS.sleep(3);
getDriver().switchTo().alert();
System.out.printf("%n*** An alert was present ***");
alertPresent=true;
}
catch (NoAlertPresentException e) {
System.out.printf("%n*** An alert was not present ***");
alertPresent=false;
}
return alertPresent;
}
現在取決於你是否警報存在與否可以直接您的流量,你這是怎麼接受的警報(是的,OK,繼續):
if (alertPresent==true){
driver.switchTo().alert().accept();
System.out.println("Successfully accepted an alert!");
}
else{System.out.println("Couldn't locate an alert!");}
希望以上解決它給你;如果沒有,不用擔心,在下面發帖子,我們會看到我們能做些什麼。
祝你好運!
只是一個愚蠢的假設,因爲我不明白爲什麼標準的http:// username:[email protected]不起作用。也許你正在使用https而不是http? :) –
它適用於https,但在網站上有些頁面被限制爲https在那種情況下警告框再次發生 –