2014-02-12 2 views

답변

1

이렇게 될 것입니다.

WebDriverWait wait = new WebDriverWait(driver, 10 /*timeout in seconds*/); 
          if(wait.until(ExpectedConditions.alertIsPresent())==null){ 
           System.out.println("alert was not present"); 
          } 
          else 
          { 
          Alert alert = driver.switchTo().alert(); 
          alert.accept(); 
          System.out.println("alert was present and accepted"); 
          } 
+0

user3122524 @ 작동하는지 알려주세요. – newLearner

0

나는이 당신을 것 같아요 :

@Test 
public void testAlertOk() 
{ 
//Now we would click on AlertButton 
WebElement button = driver.findElement(By.id("AlerButton")); 
button.click(); 
try { 
//Now once we hit AlertButton we get the alert 
Alert alert = driver.switchTo().alert(); 
//Text displayed on Alert using getText() method of Alert class 
String AlertText = alert.getText(); 
//accept() method of Alert Class is used for ok button 
alert.accept(); 
//Verify Alert displayed correct message to user 
assertEquals("this is alert box",AlertText); 
} catch (Exception e) { 
e.printStackTrace(); 
} 
} 

출처 : Click here for more detail understanding

관련 문제