How can Selenium Chrome WebDriver notifications be handled in Python?
Have tried to dismiss/accept alert
and active element
but seems notifications have to be treated other way. Also, all the Google search results are driving me to Java solution which I do not really need. I'm a newbie in Python.
Thanks in advance.
You can disable the browser notifications, using chrome options.
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
In December, 2021, using ChromeDriver Version: 96, the python code structure would look like below to handle the ChromeDriver/ Browser notification:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Creating Instance
option = Options()
# Working with the 'add_argument' Method to modify Driver Default Notification
option.add_argument('--disable-notifications')
# Passing Driver path alongside with Driver modified Options
browser = webdriver.Chrome(executable_path= your_chrome_driver_path, chrome_options= option)
# Do your stuff and quit your driver/ browser
browser.get('https://www.google.com')
browser.quit()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With