During my form testing, I encountered a javascript alert in my web app notifying users to fill in missing data if needed data is not typed. The problem arises when using selenium to handle this alert, as an exception occurs when trying to submit the partially filled form.
org.openqa.selenium.UnhandledAlertException: Modal dialog present
Attempting to catch this exception results in the webdriver alert not being displayed. Is there any solution to overcome this issue? I want to be able to submit the form and capture the alert. My setup includes Linux Mint, Firefox 18, and selenium 2.28.0 with Java. Best regards UPDATE My code contains the following:
somePage.fillName(sth); // Only one of two required fields are filled
somgePage.submit(); // JS alert appears after clicking submit
somePage.getCurrentAlert();
// Code snippets
public Alert getCurrentAlert(){
return driver.switchTo().alert();
}
public AdminHome submit(){
saveUrl();
WebElement submit = driver.findElement(By.id("add_quiz_submit_button"));
try{
submit.click();
if(urlChanged()){
return new AdminHome(driver);
}
}
catch(Exception e){
e.printStackTrace();// Exception 1
return null;
}
return null;
}
//Exception 1
org.openqa.selenium.UnhandledAlertException: Modal dialog present
//The test fails because of:
org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information)
However, manually clicking on submit works as expected for the test. Thank you in advance