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。
错误 :登录凭证无效。 –