selenium java等待alert对话框弹出,并关闭对话框


private void waitForAlertAndCloseAlert(WebDriver driver) throws InterruptedException
	  {
	     int i=0;
	     while(i++<10)
	     {
	          try
	          {
	              Alert alert = driver.switchTo().alert();
	              alert.accept();
	              break;
	          }
	          catch(NoAlertPresentException e)
	          {
	            Thread.sleep(1000);
	            continue;
	          }
	     }
	     if(i==9){
	    	 throw new NoAlertPresentException();
	     }
	  }




你可能感兴趣的:(selenium,java)