|
我用Selenium2.0做个登陆测试,不输入用户名和密码直接点登录,想验证弹出的alert信息
下面是代码:
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://localhost:8080/");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement loginButton = driver.findElement(By.id("j_login"));
loginButton.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Alert alert = driver.switchTo().alert();
if (null == alert) throw new NoAlertPresentException();
verfyLogin("请输入用户登录名",alert.getText());
alert.accept();
}
public static void verfyLogin(String x,String y){
System.out.println(y);
if(x.equals(y)){
System.out.println("true");
}else{
System.out.println("false");
}
}
上面程序用firefor允许没有问题,但是换成ie允许,就会报错Exception in thread "main" org.openqa.selenium.NoAlertPresentException: No alert is active
发现用ie允许的时候按钮是点击了,但是没有alert的弹出框。
请教各位谁有遇到过这种情况,是如何解决的,谢谢! |
|