0
我的測試檢查用戶是否可以登錄到該站點。 我寫了一個代碼來提醒該作品,但在catch
中顯示部分。 我試圖在沒有try
和catch
的情況下寫入警報,但顯示錯誤。不顯示警報
如何在沒有try
和catch
的情況下編寫報警,並顯示警報(測試通過)。
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for alert to be present (tried for 5 second(s) with 500 MILLISECONDS interval)
這是我的代碼:
public void getMessage() {
//Verify that is message preview
try {
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
System.out.println(alert.getText());
alert.accept();
Assert.assertTrue(alert.getText().contains("ERROR: Invalid login credentials."));
} catch (Exception e) {
System.out.println("Alert is not displayed");
}
那麼問題是什麼? – Andersson
我的猜測是警報是HTML對話框而不是JS警報。當警報彈出時,右鍵單擊它。如果您獲得右鍵單擊上下文菜單並可以檢查,那麼它是基於HTML的,而不是警報。 – JeffC
是的,這是html。
錯誤 :登錄憑證無效。 –