[英]Input area text alert doesn't dismiss in SeleniumPlus Internet Explorer test
所以我有一個自動測試中的方法VerifyAndDismissAlert()
try{
WebDriver WD = WebDriver();
Alert alert = WD.switchTo().alert();
alert.accept();
String alertText = alert.getText();
Pause(1);
SeleniumPlus.VerifyValues(AlertTextToVerify, alertText);
} catch (Exception e) {
e.printStackTrace();
}
當在Chrome中運行時,當嘗試在輸入框中輸入內容時,警報會彈出並消失。
但是,在Internet Explorer中,警報會彈出並且不會消失。 似乎警報甚至無法識別,因為當我被迫單擊“確定”繼續測試時,它會拋出
org.openqa.selenium.NoAlertPresentException: No alert is active
此測試與Chrome驅動程序完美配合,因此它必須與IE驅動程序一起執行某些操作。 任何幫助,將不勝感激!
使用ExpectedConditions等待警惕存在,你越來越alert.getText()
通過接受警報后alert.accept();
這肯定會引發NoAlertPresentException。因為接受后警報不會在那里。 在接受或關閉警報之前,您已經對Alert.getText()之類的警報進行了操作
WebDriverWait wait = new WebDriverWait(WD, 30);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = WD.switchTo().alert();
String alertText = alert.getText();
System.out.println(alertText);
alert.accept();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.