'How to disable chrome notifications popup in python and selenium?
How to disable chrome notifications popup in python and selenium?
I tried:
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)
But then also it shows notification...
I tried the same codes answered here but then also I am not able to disable the notifications!
Solution 1:[1]
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)
Solution 2:[2]
from selenium import webdriver
chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('disable-notifications') driver = webdriver.Chrome(executable_path="C:\Users\PycharmProjects\chromedriver_win32\chromedriver.exe", options=chrome_options) driver.maximize_window()
This works with the right placement of code: Click here for Image-->ChromeOptions Pycharm Code Image
Solution 3:[3]
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 } );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JeffC |
| Solution 2 | |
| Solution 3 | codemon |

