First lets discuss what is browser notification?
Lot of websites have started sending notifications these days. You get these notification on desktop or device even when the concerned web page is not open in your browser. These are also called as Web push notifications. These notifications looks like below in firefox and chrome browser:
Browser Notification In Firefox
You can see this notification by visiting to jabong.com website.
Browser Notification In Chrome
You can see this notification by visiting to https://drupal-stage-web.weather.com website.
If we need to handle browser notification using Selenium in Firefox browser, we should use following code:
1 2 3 4 5 6 7 8 9 |
<span style="color: #000000;">public class Test { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","./Resource/geckodriver.exe"); FirefoxProfile ffprofile = new FirefoxProfile(); ffprofile.setPreference("dom.webnotifications.enabled", false); WebDriver driver = new FirefoxDriver(ffprofile); driver.get("https://jabong.com"); } }</span> |
While using this code, make sure gecko driver path is correctly configured. In case, you are not aware of Firefox Profile Class. Please visit below Selenium java doc to know more about its methods and usage.
http://seleniumhq.github.io/selenium/docs/api/java/index.html
If we need to handle browser notification using Selenium in Chrome browser, we should use following code:
1 2 3 4 5 6 7 8 9 10 11 |
<span style="color: #000000;">public class Test { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","./Resource/chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-notifications"); WebDriver driver = new ChromeDriver(options); driver.get("https://drupal-stage-web.weather.com"); } }</span> |
While using this code, make sure chrome driver path is correctly configured. In case, you are not aware of Chrome Options Class. Please visit below Selenium java doc link provided above.
Do let us know if any issue is faced while handling browser/ web push notifications using selenium.
One Comment
Thanks for this. Fixed firefox notifications issue by this fix..