'How to handle chrome notification pop-up using selenium webdriver?
If any one logged inside any application using chrome browser,notification pop-up appears to save password/Allow notification. How to handle this notification pop-up through selenium web-driver? Sometimes two pop-ups appears(one is for save password and another one is to allow notification).I have already tried to handle using Alert class but could not succeeded.kindly help me on this.
Solution 1:[1]
You can open use ChromeOptions Class. Below is the sample code.
ChromeOptions chrome_Profile = new ChromeOptions();
chrome_Profile.addArguments("chrome.switches","--disable-extensions");
chrome_Profile.addArguments("--disable-save-password");
chrome_Profile.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver","c/chromedriver.exe");
//Passing chrome_Profile while initializing the ChromeDriver
WebDriver driver = new ChromeDriver(chrome_Profile);
Let me know if this helps.
Solution 2:[2]
You can use below code to allow chrome to send notifications:
ChromeOptions options=new ChromeOptions();
Map<String, Object> prefs=new HashMap<String,Object>();
prefs.put("profile.default_content_setting_values.notifications", 1);
//1-Allow, 2-Block, 0-default
options.setExperimentalOption("prefs",prefs);
ChromeDriver driver=new ChromeDriver(options);
Solution 3:[3]
@Pritesh patel
it didnt work for me.. I want to allow the flash to run
package com.selenium.Basics;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import Flash.FlashObjectWebDriver;
public class GuruPgm14FlashTesting {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String driverPath="C:\\selenium\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeOptions options=new ChromeOptions();
Map<String, Object> prefs=new HashMap<String,Object>();
prefs.put("profile.default_content_setting_values.notifications", 1);
//1-Allow, 2-Block, 0-default
options.setExperimentalOption("prefs",prefs);
WebDriver driver=new ChromeDriver(options);
driver.get("http://demo.guru99.com/test/flash-testing.html");
Thread.sleep(5000);
driver.findElement(By.xpath("//embed[@play='false']")).click();
System.out.println("Clicked to allow the addon");
Thread.sleep(5000);
FlashObjectWebDriver fdriver= new FlashObjectWebDriver(driver, "myFlashVideo");
fdriver.callFlashObject("Play");
Thread.sleep(5000);
fdriver.callFlashObject("StopPlay");
Thread.sleep(5000);
fdriver.callFlashObject("SetVariable","/:message","Flash testing using selenium Webdriver");
System.out.println(fdriver.callFlashObject("GetVariable","/:message"));
}
}
Solution 4:[4]
const webdriver = require('selenium-webdriver');
var chromeCapabilities = webdriver.Capabilities.chrome();
var chromeOptions = {
'args': ['--disable-notifications']
};
chromeCapabilities.set('chromeOptions', chromeOptions);
If you are using js. Especially when website adding now option to provide add on your screen or even the www dot come want to send you notification, this ultimately makes your windows blackened and inaccessible to element in it. Try to put this on a different JS file if u do. Cause export is a function
Solution 5:[5]
in Python:
if browser == "chrome":
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.driver.maximize_window()
self.driver.implicitly_wait(10)
Solution 6:[6]
You can use ChromeOptions class to allow / disable notification popup.
Please find code below :
Map<String, Object> prefs = new HashMap<String, Object>();
// 1 for allowing, 2 for disabling popup
prefs.put("profile.default_content_setting_values.notifications", 1);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
Solution 7:[7]
We can disable all type chrome notifications such as save password, allow locations..., just by adding only one argument.
ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", ""c/chromedriver.exe"");
WebDriver driver = new ChromeDriver(ops);
hope this helps you. Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alok |
| Solution 2 | Papershine |
| Solution 3 | Shiv |
| Solution 4 | Hung John |
| Solution 5 | Raghwendra Sonu |
| Solution 6 | mate00 |
| Solution 7 | santhosh kumar |
