• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Basic Selenium / How to Disable Chrome notifications in Selenium WebDriver

How to Disable Chrome notifications in Selenium WebDriver

October 10, 2016 by Mukesh Otwani 32 Comments

Disable Chrome notifications Selenium

I am sure that you might have faced notification bar in Selenium while working with Chrome Browser. In this article, I will guide you how to Disable Chrome notifications Selenium webdriver.

In previous, post we also discussed how to disable developer option mode in Selenium. 

If you have not faced any scenario like this then check below screenshot to check how it looks.

 

Disable Chrome notifications Selenium

 

Program to Disable Chrome notifications Selenium Webdriver

import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class HandlePopup {

	public static void main(String[] args) throws Exception {
		
                // Create object of HashMap Class
		Map<String, Object> prefs = new HashMap<String, Object>();
              
                // Set the notification setting it will override the default setting
		prefs.put("profile.default_content_setting_values.notifications", 2);

                // Create object of ChromeOption class
		ChromeOptions options = new ChromeOptions();

                // Set the experimental option
		options.setExperimentalOption("prefs", prefs);

                // pass the options object in Chrome driver

		WebDriver driver = new ChromeDriver(options);
		driver.get("https://www.facebook.com/");
		driver.manage().window().maximize();
		driver.findElement(By.id("email")).sendKeys("urid");
		driver.findElement(By.id("pass")).sendKeys("urpass");
		driver.findElement(By.id("loginbutton")).click();
		
		
	}

}

 

I hope this post might help if yes then kindly share with your friends.

Filed Under: Basic Selenium Tagged With: Disable Chrome notifications Selenium, Handle popup in Selenium, How to Disable Chrome notifications Selenium

Reader Interactions

Comments

  1. Risha says

    December 8, 2020 at 11:12 PM

    Hello Mukesh ,
    Thanks for your amazing videos that are helping me to solve many issues in automation , i just need to know how to deal the onesignal slidedown that we get on many website stating”We’d like to send you notifications for the latest news and updates.” allow and cancel button. using selenium !

    Reply
    • Mukesh Otwani says

      December 9, 2020 at 1:37 PM

      Hi Risha,

      You need to use ChromeOptions to deal with it as mentioned here chromeOptionsObj.addArguments(“–disable-notifications”);

      Reply
  2. ramana says

    January 8, 2020 at 3:45 AM

    Hi Mukesh
    How to disable geolocation popup blockers in firefox browsers . I am unable to use alert functions in webdriver io to disable and enable location pop ups.

    Reply
    • Mukesh Otwani says

      January 9, 2020 at 4:37 PM

      Hi Ramana,

      Use FirefoxOptions as mentioned below
      FirefoxOptions option = new FirefoxOptions();
      option.addPreference(“geo.enabled”, false);

      and let me know with your observations

      Reply
  3. sunil dev prasad says

    July 9, 2019 at 2:57 PM

    Hi Mukesh,

    Thanks for your continuous support. I stuck with an issue ,where my scripts are running fine in local machine but when i tried to run through Jenkins(our Vm’s are located in a different location(AWS)) it is failing to navigate to my homepage.Error is Unable to find element . It is giving that error in Production node whereas when i am running those in UAT3 through Jenkins my Script is wkng fine.

    Reply
    • Mukesh Otwani says

      July 9, 2019 at 5:31 PM

      Hi Sunil,

      Just want to know that is there any SSO/other auth type required to login into application because I’ve seen this scenario some applications. Usually in local env, SSO works and no need to take care of login page but while executing on remote machines, it requires username and password as authentication.

      Reply
  4. pradeep says

    May 17, 2019 at 5:16 PM

    Hi Mukesh,Unable to select Drop down ajax value selenium webdriver .can you please tel me the way of select drop down box when it is in ajax script

    Reply
    • Mukesh Otwani says

      May 17, 2019 at 6:22 PM

      Hi Pradeep,

      Probably it might not have select tag so in this case, please refer this link for idea to implement workaround.

      Reply
  5. pradeep says

    May 9, 2019 at 12:20 PM

    Hi mukesh,i have written selenium script for facebook login .after login face book account then problem occur allow notifications .how to close allow notifications in Firefox browser .let me know the solution please

    Reply
    • Mukesh Otwani says

      May 9, 2019 at 1:22 PM

      Hi Pradeep,

      I hope that you went through my post carefully, isn’t? Because I also took same fb login example.

      Reply
  6. Meet says

    March 26, 2019 at 3:42 PM

    Hi Mukesh, All the solutions available online are for scenario where user gets notification as soon as webpage appears. In my case, I want to handle notification after opening webpage and performing many steps. I am actually clicking on record audio button on the page and then I need to allow. Help would be much appreciated. Thanks!!

    Reply
    • Mukesh Otwani says

      March 27, 2019 at 6:29 PM

      Hi Meet,

      As of now, Selenium doesn’t allow to notofication pop up as per your requirement beacuse these kind of notification pop up doeosn’t come on Web UI. You can look chromeoptions for allow option for notification pop up.

      Reply
  7. Brian says

    January 26, 2017 at 1:08 AM

    Hello
    How do you block geolocation?

    Reply
    • Mukesh Otwani says

      January 30, 2017 at 9:50 AM

      Hi Brian,

      Try with this chrome option options.addArguments(“–disable-geolocation”) and please reply back.

      Reply
      • Arpita says

        September 15, 2023 at 4:36 PM

        Hi Mukesh, I am trying to block geolocation with webdriver manager but it’s not working, can you suggest anything?

        Reply
        • Mukesh Otwani says

          October 9, 2023 at 1:54 PM

          Hi Arpita, sure I can help. Which application you are trying to automation and what is your code snippet.

          Reply
  8. Shambo says

    January 21, 2017 at 12:32 PM

    Hi Mukesh,

    In interviews they demand each and every line explanation of the code.And also i cannot understand the code.Can u please explain the code that u have written??

    Reply
    • Mukesh Otwani says

      January 21, 2017 at 1:20 PM

      Hi Shambo,

      It is better if you do some project work in order to automate a web application. Then only you will gain some knowledge and feel confident.

      Reply
  9. Nathasha says

    January 9, 2017 at 3:28 PM

    Hello Mukesh,
    Can you please explain me “options.setExperimentalOption(“prefs”, prefs);”

    Reply
    • Mukesh Otwani says

      January 9, 2017 at 6:10 PM

      Hi Natasha,

      Using this we can change/set default behavior of chrome browser. Set as many options you want and put them in hashmap. Later on using above statement, set all those options in one shot.

      Reply
      • Nathasha says

        January 10, 2017 at 6:28 PM

        thank you, Mukesh.

        Reply
        • Mukesh Otwani says

          January 10, 2017 at 7:13 PM

          Hi Natasha,

          Thanks for your reply comments

          Reply
  10. Rajesh says

    November 4, 2016 at 11:11 AM

    Hi Mukesh
    When I was execute my code the below error displayed some time.
    Element is not currently visible and so may not be interacted with (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 9 milliseconds
    Build info: version: ‘2.53.1’, revision: ‘a36b8b1’,
    System info:os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_111’
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.1,
    platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true,
    browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

    Reply
    • Mukesh Otwani says

      November 5, 2016 at 10:42 PM

      Hi Rajesh,

      Kindly follow below guide

      http://learn-automation.com/solve-elementnotvisibleexception-in-selenium-webdriver/

      Reply
  11. Abbas says

    October 24, 2016 at 4:39 PM

    Hi Mukesh,

    Can you please explain the line: prefs.put(“profile.default_content_setting_values.notifications”, 2);
    I mean what does the number 2 in the above line specifies ?

    Reply
    • Mukesh Otwani says

      October 25, 2016 at 1:56 PM

      0- Default
      1- Allow
      2- Block

      Reply
      • Sanjana says

        May 16, 2019 at 12:17 PM

        I want to allow the popup & for that I am setting it to 1, but it didn’t work for me.
        Is there any other solution for this?

        Reply
        • Mukesh Otwani says

          May 17, 2019 at 6:27 PM

          Hi Sanjana,

          Could you please try without any chrome options and let me know with observartions.

          Reply
  12. manju says

    October 12, 2016 at 7:08 PM

    Hi Mukesh sir Plz in the code chrome driver path is missing.so,it’s coming some error

    Reply
    • Mukesh Otwani says

      October 13, 2016 at 8:51 AM

      HI Manju,

      Its not missing I am using MAC so I did below setting so I don’t have to mention path of chrome again and again http://learn-automation.com/chrome-browser-on-mac-using-selenium/

      Reply
  13. Mohammed Fareed says

    October 11, 2016 at 4:39 PM

    Hi Mukesh! Hope you are doing great!
    I have 1 query related to the Sikuli. 1 of my colleagues has used this method to drag and drop a file from the local folder in the system to the application. But he has used the image as path and then later gave the commands such as driver.doubleclick(..); but I want to know it from you clearly on how to use this method. Kindly guide me to the scenario where it is required for us to drag a file from a local folder to the web application. also please let me know other uses of Sikuli and also how we configure it.

    Reply
    • Mukesh Otwani says

      October 12, 2016 at 11:42 AM

      Hi Fareed, sure I will make one post on this.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

Video Player
https://www.youtube.com/watch?v=w_iPCT1ETO4
00:00
00:00
31:21
Use Up/Down Arrow keys to increase or decrease volume.

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?