I can't close a window using driver.close() method. When it gets executed, an alert appears.
I tried
JavascriptExecutor js = (JavascriptExecutor) driver;
String script = "window.onbeforeunload = null;";
js.executeScript(script);
driver.close();
I can't even accept the alert. driver.switchTo().alert().accept()
is not executed.
I also tried
driver.close();
System.out.println("After closing the window");//This line is not executed.
Control just stops at driver.close()
and no exception is thrown and the following lines are not executed.