While surfing the internet, everyone must have come across so many websites that send notifications. Those notifications can be on a 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 the Google Chrome browser:-

On a side note, we would like to mention about WooCommerce Push Notification plugin that we have developed allowing merchants to send custom push notifications to subscribers.
Step-by-step execution of Code:-
We have to follow the below-mentioned steps to handle these notifications:-
1: Create an instance of ChromeOptions class
ChromeOptions options = new ChromeOptions();
2: Add chrome switch to disable notification – “–disable-notifications”
options.addArguments("--disable-notifications");
3: Set path for the chrome driver
System.setProperty("webdriver.chrome.driver", "/home/users/garima.pathak/Desktop/softwares/chromedriver");
4: Pass ChromeOptions instance to ChromeDriver Constructor
WebDriver driver =new ChromeDriver(options);
5: Give the navigation of the page on which we want to handle the notifications.
driver.get("http://wordpressdemo.webkul.com/wordpress-latest-tweets/");
Code:-
The complete code will look like this:-
package automationFramework; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class Notifications { public static void main(String[] args) { ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-notifications"); System.setProperty("webdriver.chrome.driver", "/home/users/garima.pathak/Desktop/softwares/chromedriver"); WebDriver driver =new ChromeDriver(options); driver.get("http://wordpressdemo.webkul.com/wordpress-latest-tweets/"); driver.manage().window().maximize(); } }
That’s all about handling the notifications using Selenium. Thanks for reading this blog 🙂 Keep coming back up for more dev blogs.
As an official WooCommerce plugin vendor, we have developed many different plugins to add more features, functionalities, and new integrations to the WooCommerce platform.
One of the most popular plugins is WooCommerce Multi Vendor, which allows third-party sellers to sell their products on the same WordPress website platform.
prefs.put(“profile.default_content_setting_values.notifications”, 2);
ChromeOptions opt= new ChromeOptions();
opt.setExperimentalOption(“prefs”, prefs);
WebDriver driver= new ChromeDriver(opt);
driver.get(“https://www.redbus.in/”);
i ahev use this code if above 50 is browser version but not working plz help