driver.executeScript("window.onbeforeunload = function(e)");
You may need to call the javascript_executor instead of exexuteScript.
You also may need to use onunload instead of onbeforeunload.
The onbeforeunload or onunload modification should be done BEFORE this popup occurs. The javascript line above is essentially zeroing out the event that would normally trigger this.
Sources
https://stackoverflow.com/questions/6852732/selenium-webdriver-how-to-close-browser-popup