繁体   English   中英

如何在 selenium 中自动启用通知?

[英]How can I automatically enable notifications in selenium?

无论如何使用selenium使用 selenium webdriver 自动激活通知? 到目前为止,我学到的东西不起作用。 即使在其他stackoverflow问题中。

这是我一直在使用的代码

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

option = Options()
option.add_argument('--enable-notifications')

driver = webdriver.Chrome("chromedriver.exe", chrome_options=option)
driver.get("https://example.com")

允许通知<\/strong>

Chrome 浏览器的默认行为是询问允许或阻止通知。 并会显示相应的对话框弹出窗口。

下一个配置将自动允许通知而不显示允许\/阻止消息:

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

option = Options()
prefs = {"profile.default_content_setting_values.notifications" : 1}
option.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome("chromedriver.exe", chrome_options=option)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM