How to disable notification popup in Chrome Browser

≡放荡痞女 提交于 2019-12-13 10:09:07

问题


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome("C:\\chromedriver\\chromedriver.exe")
driver.maximize_window()
driver.get("https://www.arttoframe.com/")
time.sleep(6)
driver.close()

Console Logs :

C:\Users\Dell\PycharmProjects\untitled\venv\Scripts\python.exe 
C:/Users/Dell/PycharmProjects/untitled/newaaa.py

Process finished with exit code 0

回答1:


As you have created an instance of ChromeOptions() as chrome_options you need to pass it as an argument to put the configurations in effect while invoking webdriver.Chrome() as follows :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get("https://www.arttoframe.com/")
time.sleep(6)
driver.quit()

Note :

  • To maximize the Chrome browser instead of maximize_window() use the ChromeOptions() class argument start-maximized
  • At the end of your program instead of driver.close() use driver.quit().


来源:https://stackoverflow.com/questions/49626707/how-to-disable-notification-popup-in-chrome-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!