您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用Selenium针对Firefox和Chrome禁用推送通知?

如何使用Selenium针对Firefox和Chrome禁用推送通知?

如果您的用 是禁用 通知,则可以使用 以下选项:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");

ProfilesIni profile = new ProfilesIni(); FirefoxProfile testprofile = profile.getProfile(“debanjan”); testprofile.setPreference(“dom.webnotifications.enabled”, false); testprofile.setPreference(“dom.push.enabled”, false); DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setCapability(FirefoxDriver.PROFILE, testprofile); FirefoxOptions opt = new FirefoxOptions(); opt.merge(dc); WebDriver driver = new FirefoxDriver(opt); driver.get("https://www.ndtv.com/”);

:此方法使用存储在我的本地系统中的现有FirefoxProfile名称为 的现有文件,该文件 文件中的文档

System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");

Map prefs = new HashMap (); prefs.put(“profile.default_content_setting_values.notifications”, 2); prefs.put(“credentials_enable_service”, false); prefs.put(“profile.password_manager_enabled”, false); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption(“prefs”, prefs); options.addArguments(“start-maximized”); options.addArguments(“disable-infobars”); options.addArguments(“–disable-extensions”); options.addArguments(“–disable-notifications”); WebDriver driver = new ChromeDriver(options); driver.get( "https://www.ndtv.com/”);

其他 2022/1/1 18:15:02 有667人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶