I am running an automated test suite in Python Selenium, but I’m blocked by the native Chrome "Show Notifications" popup that appears right after the page loads. Since this is a browser-level dialog and not part of the HTML DOM, my driver can't locate the "Allow" button using standard XPaths. Is there a specific ChromeOptions or DesiredCapabilities setting that can pre-configure the browser to automatically accept these notifications or disable the prompt entirely during execution?
3 answers
Because notification prompts are part of the browser's native UI and not the webpage, you cannot interact with them using find_element. The industry-standard solution is to use ChromeOptions to modify the browser preferences before the driver starts. You need to create an experimental option called prefs and set profile.default_content_setting_values.notifications to 1 to allow them, or 2 to block them. This injects the permission directly into the browser profile, so the popup never even appears to interrupt your script.
By handling this at the driver initialization stage, your tests remain stable and won't get stuck waiting for a click that the WebDriver cannot physically perform.
Does this method of using experimental options also work for other permissions, like "Location" or "Microphone" access, or do those require different preference keys within the ChromeOptions object?
The easiest way is to use the --disable-notifications argument in your options. It completely suppresses the popup so your test can continue without any extra logic.
I agree with Jennifer. For most SEO and scraping tasks, you don't actually need the notifications to work; you just need the popup out of the way. The --disable-notifications flag is the cleanest one-liner to keep the automation moving smoothly.
Christopher, yes, the logic is identical. For location, you would use profile.default_content_setting_values.geolocation, and for media streams, it is profile.default_content_setting_values.media_stream_mic. Setting these values to 1 essentially "pre-clicks" Allow for the automation session. I’ve used this extensively for testing mapping applications where the location prompt used to break my head-less CI/CD builds every single time.