JavascriptExecutor worked for me. Just make sure you execute it before clicking the event that triggers the warning.
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");
Note: - do not use it after clicking on an event that brings up a warning confirmation window. Above the default code, set the confirmation field as true means that you accept / click ok in any confirmation window on this page, if called
Hope this helps you :)
source share