webdriver中处理alert

1 定义isAlertPresent()供调用;

public  boolean isAlertPresent() {
  try {
   driver.switchTo().alert();
   return true;
  } catch (NoAlertPresentException Ex) {
   return false;
  }
 }

2 处理弹出的alert;

while (new Sgzzsjps_Action(driver).isAlertPresent()){ 
            driver.switchTo().alert().accept(); 
           Thread.sleep(3000);
           } 

posted @ 2016-01-05 16:28  tiancy  阅读(338)  评论(0编辑  收藏  举报