0

On facebook, if I go to main page, and I get this annoying notification:

fb

I try to bypass (not working) with:

options = webdriver.ChromeOptions()
options.add_experimental_option(
    "prefs",
    {
        "credentials_enable_service": False,
        "profile.password_manager_enabled": False,
        "profile.default_content_setting_values.notifications": 2           
        # with 2 should disable notifications
    },
)
# one more time
options.add_argument('--disable-notifications') 
options.add_argument("--password-store=basic")
options.add_argument("--disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("start-maximized")

2 Answers2

0

My bad, forgot to use options=options after the code I provided:

s = Service('/path/to/chromedriver')
driver = webdriver.Chrome(service=s, options=options) # < there -_

So:

options = webdriver.ChromeOptions()
options.add_experimental_option(
    "prefs",
    {
        "credentials_enable_service": False,
        "profile.password_manager_enabled": False,
        "profile.default_content_setting_values.notifications": 2           
        # with 2 should disable notifications
    },
)
options.add_argument('--disable-notifications') 
options.add_argument("--disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("start-maximized")
s = Service('/path/to/chromedriver')
driver = webdriver.Chrome(service=s, options=options) 
driver.get('http://example.org')
0

It works for me,

from selenium import webdriver
from selenium.webdriver import ChromeOptions, Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time

options = ChromeOptions()

options.add_argument("--start-maximized")
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option(
    "prefs",
    {
        "credentials_enable_service": False,
        "profile.password_manager_enabled": False,
        "profile.default_content_setting_values.notifications": 2
        # with 2 should disable notifications
    },
)

driver = webdriver.Chrome(options=options)

url = "https://www.facebook.com/"
driver.get(url)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "globalContainer")))
container = driver.find_element(By.ID, "globalContainer")

# fill the email account, password
email = container.find_element(By.ID, 'email')
password = container.find_element(By.ID, 'pass')
email.send_keys("xxxxxxxxxxxxxxxxx")
password.send_keys("xxxxxxxxxxxxxxxxxxx")
password.send_keys(Keys.ENTER)
time.sleep(5)
Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24