3

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...

notifications popup image

I tried the same codes answered here but then also I am not able to disable the notifications!

Community
  • 1
  • 1
Slook
  • 63
  • 1
  • 6

3 Answers3

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)
JeffC
  • 22,180
  • 5
  • 32
  • 55
pelelter
  • 518
  • 4
  • 14
  • Please consider explain your approach though it pretty straight forward. Adding a few comment on explain the code and how it work in the case of OP would be very helpful. – Sinh Nguyen Apr 13 '21 at 14:00
0

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

sathish
  • 149
  • 1
  • 4
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 02 '22 at 09:44
-1

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 } );
codemon
  • 1,456
  • 1
  • 14
  • 26