Menu Close
    Hire us 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 (51)

    Add Your Comment

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

  • 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 received your message and our expert will get back to you shortly.
    Send Again