Here's the code snippet I'm working with. While it successfully removes the alert box, it throws an error in the console:
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: If you leave this page, any changes will be lost. Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'"I am using Internet Explorer 11.
driver.findElement(By.xpath("//div[@id=ctl02_cp1_ucGI")).click();
Thread.sleep(4000);
if (ExpectedConditions.alertIsPresent() != null)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.onbeforeunload = function() {};");
System.out.println("alert is present");
}
else
{
System.out.println("alert is not present");
}
Thread.sleep(4000);
WebElement product1=driver.findElement(By.xpath("//select[@id='ctl00_cp1_ucGI_ddlProduct']"));