3

I know this is an old question, and I've tried answers from a few posts such as Disable Chrome notifications (Selenium)

Unfortunately none worked, the browser notification popup still comes and interrupts my simulations.

My Chrome version is 75.0.3770.100 (Official Build) (64-bit), running on MacOS.


Edit:

After this question was marked as a duplicate of How to disable push-notifications using Selenium for Firefox and Chrome?, I've tried the solutions, but it still did not work for me.

            String chromePath = "somepath/selenium-2.48.2/chromedriver";
            System.setProperty("webdriver.chrome.driver", chromePath);


            Map<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_setting_values.notifications", 2);
            prefs.put("credentials_enable_service", false);
            prefs.put("profile.password_manager_enabled", false);
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", prefs);
            options.addArguments("start-maximized");
            options.addArguments("disable-infobars");
            options.addArguments("--disable-extensions");
            options.addArguments("--disable-notifications");

            driver = new ChromeDriver(options);

Below are the original solutions I tried.

        String chromePath = "somepathto/chromedriver";
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--disable-notifications");
        System.setProperty("webdriver.chrome.driver", chromePath);
        WebDriver driver = new ChromeDriver(chromeOptions);

        // Login
        try {
            driver.get(sometestURL);
            driver.manage().window().maximize();    
            // do some operations
        } catch (Exception ex) {
            System.out.println(ex);
        }

I also tried this:

        String chromePath = "somepath/selenium-2.48.2/chromedriver";
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_content_setting_values.notifications", 2);
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setExperimentalOption("prefs", prefs);
        System.setProperty("webdriver.chrome.driver", chromePath);
        WebDriver driver = new ChromeDriver(chromeOptions);

But the notification still comes "xxxxwebsite wants to show notifications Allow Block" on the upper left of the window.

What I did not do right?

jkdev
  • 9,037
  • 14
  • 52
  • 75
user2751691
  • 383
  • 2
  • 7
  • 28
  • 1
    Few more flags you can try `--disabled-new-style-notification` and `--allow-silent-push`, also do a `ps aux | grep -i chrome` and make sure that the flag did get passed to the chrome executable when it was launched – Tarun Lalwani Jul 20 '19 at 01:31
  • Which version of Selenium you are using ? If you are using Selenium version < 3.6 . It may not work with Chrome version is 75.0.3770.100 . As chromOptions key was changed in 3.6 https://github.com/SeleniumHQ/selenium/commit/2a7e5342fa20644ff86b25de6fbabd4264659296 . Try with latest version of selenium – Rahul L Jul 26 '19 at 05:31
  • Hm, maybe. I just checked the sample project I used to verify my answer below. I used Selenium 3.14.0 and also updated the answer in order to mention it there. – kriegaex Aug 02 '19 at 06:16

1 Answers1

0

I just tested this on Windows with Chrome 75.0.3770.142 (64 bit) and ChromeDriver 75.0.3770.90 (see log below) against web site https://www.nzz.ch (because it asks for permission to show push notifications). I used Selenium 3.14.0.

08:27:37.184 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\xxxxx\.m2\repository\webdriver\chromedriver\win32\75.0.3770.90\chromedriver.exe
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}) on port 32864

For me the switch also mentioned here and in the linked resources reliably deactivates the popup from being displayed:

options.addArguments("--disable-notifications");

Changing the default setting profile.default_content_setting_values.notifications is not necessary in my case. So if this does not work for you

  • either you are not setting the option correctly,
  • you are using a (possibly outdated) ChromeDriver version not supporting it or
  • for some reason on MacOS the driver does not implement it.

P.S.: In both Firefox and Chrome for me it was not problem to e.g. click links and navigate to other pages even during the notification pop-up was shown. Did you have any problems there or is the pop-up just an annoyance?

kriegaex
  • 50,139
  • 12
  • 92
  • 145