0

I'd like to stop all Chrome Browser notifications whenever I run a selenium python file.

Example of what I'm referring to:

enter image description here

I found the following code online that theoretically blocks all chrome browser notifications:

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

option = Options()
option.add_argument('--disable-notifications')
***driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=option)
driver.get("https://www.example.com")

However, whenever I run the code, I get the following error at the *** line:

enter image description here

Any help would be greatly appreciated. Thank you.

1 Answer 1

2

To make disabled cookies/notifications/click accept, you can try as follows:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()

#enabled/disabled cookies/notifications/click accept.
option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")

#chrome to stay open
option.add_experimental_option("detach", True)

# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", { 
    "profile.default_content_setting_values.notifications": 2 
})

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get("https://www.example.com")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.