I am facing an issue where I am unable to close a window using the driver.close() method. Each time I try to execute it, an alert pops up.
One solution I attempted was:
JavascriptExecutor js = (JavascriptExecutor) driver;
String script = "window.onbeforeunload = null;";
js.executeScript(script);
driver.close();
However, even accepting the alert with
driver.switchTo().alert().accept()
is not working for me.
Another approach I tried involves:
driver.close();
System.out.println("After closing the window");//However, this line does not get executed.
It seems that the control simply halts at driver.close()
, without throwing any exceptions or allowing the subsequent lines to be executed.