Software Development

How to automatically click "Allow" on the browser "Show Notifications" permission popup in Selenium?

KI Asked by Kimberly Lawson · 14-06-2025
0 upvotes 13,883 views 0 comments
The question

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

0
AM
Answered on 18-08-2025

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.

0
CH
Answered on 22-09-2025

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?

MA 25-09-2025

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.

0
JE
Answered on 05-11-2025

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.

KI 08-11-2025

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.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session