如何接受 Chrome 通知 Selenium
How To Accept Chrome Notifications Selenium
Notification Example
我一直都在堆栈溢出,但是 2018 年的所有 selenium 东西都不适合我,有人可以告诉我如何更改 cookies/disable notifications/click accept.
None 我现在正在做的三件事中正在发挥作用
import selenium
import random
import keyboard
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
service = ChromeService(executable_path=ChromeDriverManager().install())
option=webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("--disable-extensions")
driver = webdriver.Chrome(service=service)
driver.set_window_size(1920, 1080)
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 2
})
我想我遗漏了 webdriver/Chrome(service=service) 位之类的东西。我在文档中找不到任何内容。
您在创建驱动程序后设置“option.add_experimental...”首选项。以前那样做。还要确保在您的新驱动程序调用中包含这些选项。
service = ChromeService(executable_path=ChromeDriverManager().install())
option=webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("--disable-extensions")
# 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, options=option)
driver.set_window_size(1920, 1080)
Notification Example
我一直都在堆栈溢出,但是 2018 年的所有 selenium 东西都不适合我,有人可以告诉我如何更改 cookies/disable notifications/click accept.
None 我现在正在做的三件事中正在发挥作用
import selenium
import random
import keyboard
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
service = ChromeService(executable_path=ChromeDriverManager().install())
option=webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("--disable-extensions")
driver = webdriver.Chrome(service=service)
driver.set_window_size(1920, 1080)
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 2
})
我想我遗漏了 webdriver/Chrome(service=service) 位之类的东西。我在文档中找不到任何内容。
您在创建驱动程序后设置“option.add_experimental...”首选项。以前那样做。还要确保在您的新驱动程序调用中包含这些选项。
service = ChromeService(executable_path=ChromeDriverManager().install())
option=webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("--disable-extensions")
# 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, options=option)
driver.set_window_size(1920, 1080)