TDD Project/Selenium Web Driver

Selenium WebDriver - Alert Control, Escape key

솔웅 2013. 12. 6. 10:46
반응형

오늘 배운 Tip 하나 정리 해 둡니다.


Alert 창 떴을 때 Control 하는 법


Alert alert = driver.switchTo().alert();

alert.accept();


public void checkAlert() {
    try {
        WebDriverWait wait = new WebDriverWait(driver, 2);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = driver.switchTo().alert();
        alert.accept();
    } catch (Exception e) {
        //exception handling
    }
}


driver.switchTo().alert().accept();
or
driver.switchTo().alert().dismiss();

// Get a handle to the open alert, prompt or confirmation
Alert alert = browser.switchTo().alert();
// Get the text of the alert or prompt
alert.getText();
// And acknowledge the alert (equivalent to clicking "OK")
alert.accept();

WebDriver driver = new FirefoxDriver();
driver.get("http://localhost:8081/TestAutomation/Escape.jsp");
driver.manage().window().maximize();

WebElement txtBxHandle = driver.findElement(By.name("txtName"));        
txtBxHandle.sendKeys("Socrates");

Actions action = new Actions(driver);
action.sendKeys(Keys.ESCAPE).perform();

WebElement BnEnable = driver.findElement(By.name("btnSubmit"));
BnEnable.click();


반응형