Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Handle Browser Level Notification Using Selenium

    While surfing internet, everyone must have came across so many websites who sends notifications. Those notifications can be on desktop or device even when that web page is not open in our browser. Generally, we call them Web push notifications. Below is the screenshot of notifications from chrome browser:-

    Step by step execution of Code:-

    We have to follow below mentioned steps to handle these notifications :-

    1:  Create a instance of ChromeOptions class

    2: Add chrome switch to disable notification – “–disable-notifications”

    3: Set path for the chrome driver

    4: Pass ChromeOptions instance to ChromeDriver Constructor

    5: Give the navigation of the page in which we want to handle the notifications.


    The complete code will look like :-

    That’s all about handling the notifications using selenium.

    Thanks for reading this blog 🙂

    . . .

    Comments (59)

    Add Your Comment

  • Vinay
    Can you please let me know how to do the same in Safari browser.
    • Praveen Pal
      we would like to inform you that you can handle notification in safari by using below code.You can try this mentioned below code.

      For running your script on safari browser you first need to add safari driver extension. you can dowload it from and then install it. Below is the sample code to use safari driver :-
      //Instantiate apple WebDriver
      WebDriver sDriver = new SafariDriver();
      //Use apple browser WebDriver to browse webpage
      //Find element on
      WebElement store = sDriver.findElement(By.xpath(“/html/body/header/div/div[2]/nav[1]/div/div[2]/ul/li/a”));
      //Click the web element above.;

  • seph
    Hi, how can I make this as a method and use when necessary? Thank you!
    • Priya Singh
      As per my understanding, you are trying to create a method for this operation and then call that method whenever required.

      Create a method under class scope.

      private static void notification() {

      your code

      public static void main(String[] args) {

      //call your method wherever required


      • seph
        Thanks for your reply. Actually yes, but I couldn’t do it, I mean I am not sure where to put WebDriverManager. I want to call web browser pop-up blocker whenever needed without writing everything..
        This didn’t work.
        public static void notification() {
        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new ChromeDriver(options);


        • Priya Singh
          Please share your full code.
  • Nischitha
    Hi, I have added the code as given above but I see that it is not updating the changes could u please help me with this
    • Priya Singh
      can you share the code and the scenario?
  • nischitha
    Hi, I need a help here.. I have used the same code, but I don’t see a difference. Could someone help me out with this
  • Aadhithyan
    Thanks. Very helpful.
    • Priya Singh
      Thanks for your feedback.
  • Gopinath
    Why should we disable notifications ?
  • thambi babu dasari
    I want to click on allow to accept the desktop notifications
    how can I do that using selenium web driver
    • Priya Singh
      Hello Thambi
      you can try the following code

      WebDriver driver ;
      FirefoxProfile profile = new FirefoxProfile();
      profile.setPreference(“permissions.default.desktop-notification”, 1);
      DesiredCapabilities capabilities=DesiredCapabilities.firefox();
      capabilities.setCapability(FirefoxDriver.PROFILE, profile);
      driver = new FirefoxDriver(capabilities);
      driver.get(“your Web site”);

      • thambi babu
        thank you..
        I want to handle it in chrome browser.
        I got a code to handle chrome notifications using chromeOptions.
        but, according to my scenario I need to make a voice call to other user in my application so once I logged in to app.. It allowing the notifications fine.. after that when I was click on voice call icon it asking the permission to allow or block microphone so how can handle this again for chrome browser. Is there any solution please let me know?
        thank you …
        • Priya Singh
          you can try this one:

          ChromeOptions options=new ChromeOptions();
          Map prefs=new HashMap();
          prefs.put(“profile.default_content_setting_values.notifications”, 1);
          ChromeDriver driver=new ChromeDriver(options);

          • surekha
            this one is not working
          • Priya Singh
            can you share the code and the scenario?
  • shaik ismail
    Thank you for your information it is very useful for me
    • Priya Singh
      Thanks for your feedback.
  • Amir Atias
    can you please share node.js code for the same ??
  • Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again