Python Forum
Python / Selenium Turning Off Alert
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python / Selenium Turning Off Alert
#1
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
Reply
#2
This site explains it pretty well: https://www.guru99.com/alert-popup-handl...enium.html
Reply
#3
Thank you, what i did try was:

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

regards

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Monitor specific line of code and get alert Olimpiarob 0 291 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  Issue closing an Modal Alert (popup) leviathan54 8 2,042 Apr-23-2019, 02:00 PM
Last Post: leviathan54
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 1,640 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020