Ted*_* G. 3 python selenium python-3.x selenium-chromedriver selenium-webdriver
如何在Python中处理Selenium Chrome WebDriver通知?
试图解雇/接受alert
,active element
但似乎通知必须以其他方式对待.此外,所有Google搜索结果都促使我使用Java解决方案,而我并不需要它.我是Python的新手.
提前致谢.
小智 11
您可以使用Chrome选项禁用浏览器通知.
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)
Run Code Online (Sandbox Code Playgroud)
2021 年 12 月,使用ChromeDriver Version: 96,Python 代码结构如下所示,用于处理 ChromeDriver/浏览器通知:
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()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6124 次 |
最近记录: |