TA的每日心情 | 无聊 2020-12-8 11:20 |
---|
签到天数: 605 天 连续签到: 1 天 [LV.9]测试副司令
|
alert是需要切换的。。。
/**
* Handling a simple JavaScript alert
*/
public static void AlertHandling(boolean acceptNextAlert, String alertText) {
try {
// Get the Alert
Alert alert = driver.switchTo().alert();
// Get the Text displayed on Alert using getText() method of Alert
// class
String textOnAlert = alert.getText();
if (acceptNextAlert) {
// Click OK button, by calling accept() method of Alert Class
alert.accept();
} else {
// Click cancel button, by calling dismiss() method of Alert
// Class
alert.dismiss();
}
// Verify Alert displayed correct message to user
Assert.assertTrue(textOnAlert.contains(alertText));
} catch (NoAlertPresentException e) {
e.printStackTrace();
}
} |
|