Disable Chrome notifications (Selenium)

36,152

Solution 1

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);

Solution 2

you can use:

chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
browser = webdriver.Chrome(chrome_options=chrome_options)

Solution 3

            ChromeOptions ops = new ChromeOptions();
            ops.addArguments("--disable-notifications");
            System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
            driver = new ChromeDriver(ops);

Solution 4

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
Share:
36,152
fabio_vac
Author by

fabio_vac

Updated on August 06, 2022

Comments

  • fabio_vac
    fabio_vac almost 2 years

    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.

  • Florian Koch
    Florian Koch almost 8 years
    Please provide mor information, not only code, like how does this work or why this is better than the existing solution
  • L_J
    L_J almost 6 years
    While this code may answer the question, providing information on how and why it solves the problem improves its long-term value
  • jnoreiga
    jnoreiga about 5 years
    This works best by passing an argument --disable-notifications to the application as of Chrome version 74
  • hungndv
    hungndv almost 5 years
    Could anyone help to use this code for C# version? Many thanks.