Hi Sir
In Chrome Browser after logging into application notification window is getting displayed.I wrote simple java class as below and it got handled.But when the same code I wrote in my framework its not working.Can you please let me know my error.Please let me know if I have to provide any more details
Simple Java class code
//Create prefs map to store all preferences
Map<String, Object> prefs = new HashMap<String, Object>();
//Put this into prefs map to switch off browser notification
prefs.put("profile.default_content_setting_values.notifications", 2);
//Create chrome options to set this prefs
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
//Now initialize chrome driver with chrome options which will switch off this browser notification on the chrome browser
//WebDriver driver = new ChromeDriver(options);
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
//System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
WebDriver driver=new ChromeDriver(options);
Code in TestBase class of my framework
public static void initialization()
{
String browserName=prop.getProperty("browser");
if(browserName.equals("chrome"))
{
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
driver=new ChromeDriver(options);
}
else if(browserName.equals("FF"))
{
System.setProperty("webdriver.gecko.driver", "F:\\geckodriver.exe");
}
I use this simple piece of code and it works
ChromeOptions ops = new ChromeOptions();
//ops.setBinary("");
//ops.setPageLoadStrategy(PageLoadStrategy.NORMAL);
ops.addArguments("--disable-notifications");
ops.addArguments("--start-maximized");
driver = new ChromeDriver(ops);
Yeah,I used this too.But what solved my issue was I updated Selenium version.
Instructor
Ashish Thakur Replied on 01/07/2020
Oh ok...good.. it worked