Python Forum

Full Version: Python / Selenium Turning Off Alert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Guys,

I'm using Selenium to interact with a few websites, on a few i get this alert:

[Image: TrgBkML.png]

is there a way i can disable all alerts? i have managaed to disable notifications, my code for initializing the driver is below.

# init driver ...
def init_driver(using_linux, proxy):
    options = Options()
    options.headless = False
    options.add_argument('start-maximized')
    options.add_argument('--disable-notifications')
    options.add_argument('--disable-extensions')
    options.add_argument('--log-level=3') 
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--ignore-ssl-errors')
    options.add_experimental_option("excludeSwitches" , ["enable-automation","load-extension"])
    prefs = {'profile.default_content_setting_values.notifications' : 2}
    options.add_experimental_option('prefs', prefs)
    if proxy == "0.0.0.0:0":
        print("--> PROXY DISABLED ...")
    else:
        print("--> USING PROXY: " + str(proxy) + " ...")
        options.add_argument('--proxy-server=%s' % proxy)
    if using_linux:
        return webdriver.Chrome("/usr/bin/chromedriver", chrome_options=options)
    else:
        return webdriver.Chrome("chromedriver.exe", chrome_options=options)
Any help would be appreciated, the script eventually stalls /breaks because of it.

best regards

Graham
Thank you, what i did try was:

driver.execute_script("window.onbeforeunload = function() {};")
And this seeems to work well.

regards

Graham
You could also probably do this. Untested though.
fp = webdriver.FirefoxProfile()
fp.set_preference("dom.disable_beforeunload", True)