Disable Chrome notifications (Selenium)

后端 未结 5 1517
暗喜
暗喜 2020-12-06 17:46

I just want to disable Chrome notifications in the Chrome opened by a Selenium Java application. (using java code)

Notifications like this one:

The

5条回答
  •  情歌与酒
    2020-12-06 18:46

    public class MultipleWindowHandle
    {
        public static void main(String[] args)
        {
            System.setProperty("webdriver.chrome.driver", "E:\\NEWSEL\\chromedriver.exe");
    
            // Create object of HashMap Class as shown below.
            Map prefs = new HashMap();
    
            // Set the notification setting it will override the default setting.
            prefs.put("profile.default_content_setting_values.notifications", 2);
    
            // Create object of ChromeOption class.
            ChromeOptions Roptions = new ChromeOptions();
    
            // Set the experimental option.
            Roptions.setExperimentalOption("prefs", prefs);
    
            // Open chrome browser.
            ChromeDriver driver = new ChromeDriver(Roptions);
            driver.get("https://my.monsterindia.com/login.html");
    
            Set id = driver.getWindowHandles();
            Object[] data = id.toArray();
            driver.switchTo().window((String)data[1]); driver.close();
        }
    }
    

提交回复
热议问题