简体   繁体   中英

How to disable chrome notifications popup in python and selenium?

How to disable chrome notifications popup in python and selenium?

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

The selenium package has a ChromeOptions class, in which you can add many arguments. One of which is 'disable-notifications' . You can pass that class to the driver class when initializing it.

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('disable-notifications')

driver = webdriver.Chrome('chromedriver.exe', options=chrome_options)

from selenium import webdriver


You can pass disable-notifications to your chrome options.

Here's an example I have using Javascript, should work the same with Python.

var o = new chrome.Options();

o.addArguments('user-data-dir=./chromeprofile');
o.addArguments('disable-infobars');
o.addArguments("disable-notifications");
o.setUserPreferences( { credentials_enable_service: false } );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM