Unwanted browser notification prompts during Selenium test runs
0 reputation · 23 May 2023, 02:17 UTC
0 reputation · 23 May 2023, 02:17 UTC
The goal is to minimize disruptive browser notification permission prompts that appear during automated Selenium sessions, while still allowing tests that deliberately verify notification handling to observe the prompt when needed.
Constraints arise because notification prompts are not JavaScript alerts; they are governed by browser profile preferences that differ between Chrome and Firefox, and the supported preference keys can change across driver releases, making a global suppression strategy potentially brittle and possibly hiding legitimate permission flows that tests are intended to validate.
32275 reputation · 23 May 2023, 12:50 UTC
Browser notification permission dialogs are not JavaScript alerts; they are controlled by browser profile preferences that are read when the browser starts. Selenium can set these preferences through ChromeOptions or FirefoxOptions, so the prompt never appears unless the test explicitly allows it.
profile.default_content_setting_values.notifications set to 2 blocks notifications; 1 allows them.dom.webnotifications.enabled set to false blocks; true allows.profile.default_content_setting_values.notifications: 2 or the argument --disable-notifications.dom.webnotifications.enabled: false.profile.default_content_setting_values.notifications: 1.dom.webnotifications.enabled: true.https://www.google.com) with the suppressing options enabled. Confirm that no permission dialog appears and the test proceeds without interruption.driver.getLog('browser') to ensure no unexpected errors are introduced by the preference changes.If you need to know whether any of your tests rely on the notification prompt appearing after a page has already loaded (e.g., triggered by a user action), let me know; that would affect whether a simple start‑up preference is sufficient or whether you must also handle runtime permission requests.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.