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
Author by
fabio_vac
Updated on August 06, 2022Comments
-
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:
The problem is that settings manually set are lost after browser's window is closed.
-
Florian Koch almost 8 yearsPlease provide mor information, not only code, like how does this work or why this is better than the existing solution
-
L_J almost 6 yearsWhile this code may answer the question, providing information on how and why it solves the problem improves its long-term value
-
jnoreiga about 5 yearsThis works best by passing an argument --disable-notifications to the application as of Chrome version 74
-
hungndv almost 5 yearsCould anyone help to use this code for C# version? Many thanks.