Using Python 3 and Chromedriver.
Suppose an automated python program is surfing the web, fetching stuff from different sources.
Disable the alert on before unload:
def super_get(url):
driver.get(url)
driver.execute_script("window.onbeforeunload = function() {};")
And now use super_get(whatever_url)
insetad of the standard driver.get(whatever_url)
Disable all alerts in page:
def super_get(url):
driver.get(url)
driver.execute_script("window.alert = function() {};")
Hope it helps somebody. Cheers.