Fxxxx Fxxxx - 10 months ago 156
Java Question

Disable Chrome notifications (Selenium)

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

Notifications like this one:

enter image description here

The problem is that settings manually set are lost after browser's window is closed.

Answer Source

This question was answered in the: "chromedriver-users" google forum. 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);