Back to Top

Handle Browser Level Notification Using Selenium

Updated 3 February 2023

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:-

web push notification

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

Start your headless eCommerce
now.
Find out More
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.

. . .

Leave a Comment

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


67 comments

  • Shakir Hussain
  • Shravan Daundkar
    • Shakir Hussain
    • Er. Shakir Husain (Moderator)
  • shivanshu
    • Praveen Pal (Moderator)
  • shivanshu
    • Praveen Pal (Moderator)
  • Vinay
    • Praveen Pal (Moderator)
  • seph
    • Priya Singh (Moderator)
      • seph
        • Priya Singh (Moderator)
  • Nischitha
    • Priya Singh (Moderator)
  • nischitha
  • Aadhithyan
    • Priya Singh (Moderator)
  • Gopinath
  • thambi babu dasari
    • Priya Singh (Moderator)
      • thambi babu
        • Priya Singh (Moderator)
          • surekha
          • Priya Singh (Moderator)
  • shaik ismail
    • Priya Singh (Moderator)
  • Amir Atias
  • Paras Verma
    • Priya Singh (Moderator)
  • mahesh
    • Paras Verma
  • Ashwin Kumar
    • Priya Singh (Moderator)
  • Qasim
    • Garima Pathak (Moderator)
  • Dipali Shimpi
    • Garima Pathak (Moderator)
  • Hitendra S Deshmukh
    • Garima Pathak (Moderator)
  • yogesh
    • Garima Pathak (Moderator)
  • Sowmiya
    • Garima Pathak (Moderator)
  • kancha
    • Garima Pathak (Moderator)
  • kancha
    • Garima Pathak (Moderator)
  • Meet
    • Garima Pathak (Moderator)
  • Rushikesh
  • Garima Pathak (Moderator)
  • Ana
    • Garima Pathak (Moderator)
      • Vikram Singh
  • Sakshi Nagpal
    • Garima Pathak (Moderator)
  • Nirmal
  • sarika
  • Ayush Bhatnagar
  • santosh
    • Garima Pathak (Moderator)
      • vrushali
        • Garima Pathak (Moderator)
          • Rahul Shaw
  • samet
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home