Turn off Chrome notifications (Selenium)

I just want to disable the Chrome notifications in Chrome opened by the Selenium Java application. (using java code)

Notifications like this:

enter image description here

The problem is that manual settings are lost after closing the browser window.

+4
source share
4 answers

This question was answered on the google forum "chromedriver-users". This is the working answer:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
+11
source

you can use:

chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
browser = webdriver.Chrome(chrome_options=chrome_options)
+6
source
            ChromeOptions ops = new ChromeOptions();
            ops.addArguments("--disable-notifications");
            System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
            driver = new ChromeDriver(ops);
+1
source

Someone needs it for Capybara or Watir, you can pass --disable-notificationsas a type argument "--start-fullscreen", "--disable-infobars". The following works:

Capybara.register_driver :chrome do |app|
  args = ["--disable-notifications"]
  Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => args})
end
0
source

Source: https://habr.com/ru/post/1620636/


All Articles