Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 761
fabio_vac Avatar asked Dec 17 '15 20:12

fabio_vac


4 Answers

you can use:

chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
browser = webdriver.Chrome(chrome_options=chrome_options)
like image 164
wailord Avatar answered Oct 14 '22 13:10

wailord


Someone needs this for Capybara or Watir, you can pass the --disable-notifications as an argument like "--start-fullscreen", "--disable-infobars". The following workes:

Capybara.register_driver :chrome do |app|
  args = ["--disable-notifications"]
  Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => args})
end
like image 41
Mesut GUNES Avatar answered Oct 14 '22 15:10

Mesut GUNES


            ChromeOptions ops = new ChromeOptions();
            ops.addArguments("--disable-notifications");
            System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
            driver = new ChromeDriver(ops);
like image 38
Vikas Garg Avatar answered Oct 14 '22 15:10

Vikas Garg


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);
like image 44
fabio_vac Avatar answered Oct 14 '22 13:10

fabio_vac