Bottom Page

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:

İmage


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
Quote
#2
This site explains it pretty well: https://www.guru99.com/alert-popup-handl...enium.html
Quote
#3
Thank you, what i did try was:

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

regards

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 1,011 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)