如何禁用python和selenium中的Chrome通知弹出窗口?
我尝试过:
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)
但是它还会显示通知...
我尝试了相同的代码answered here,但后来我也 无法禁用通知!
答案 0 :(得分:0)
您可以将disable-notifications
传递给Chrome选项。
这是我使用Javascript的示例,应该与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 } );
答案 1 :(得分:0)
selenium 包有一个 ChromeOptions
类,您可以在其中添加许多参数。其中之一是'disable-notifications'
。您可以在初始化时将该类传递给驱动程序类。
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('disable-notifications')
driver = webdriver.Chrome('chromedriver.exe', options=chrome_options)