Reputation: 11
I've been working on a script to automate a task in Google Chrome. Unfortunately, I haven't had any luck in giving Chrome access to my microphone and denying access to notifications. I have tried using Options().add_experimental_option()
but without any luck. Am I doing something wrong or is there another way? I have tried using fake UI and fake media stream to remove the popup, but that hasn't worked either. Options().add_argument("--use-fake-ui-for-media-stream"); Options().add_argument("--use-fake-device-for-media-stream")
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
Options().binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
Options().add_argument("start-maximized");
Options().add_argument("--disable-infobars")
# 1 to allow, 2 to block
Options().add_experimental_option("prefs", { \
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 2,
"profile.default_content_setting_values.geolocation": 2,
"profile.default_content_setting_values.notifications": 2
})
driver=webdriver.Chrome(".\chromedriver.exe", options=Options())
Upvotes: 1
Views: 5261
Reputation: 193388
You need to add all the attributes, arguments and experimental option within a single instance of Options
and pass as an argument while initiating the ChromeDriver / google-chrome combo as follows:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
options.add_argument("start-maximized")
options.add_argument("--disable-infobars")
# 1 to allow, 2 to block
options.add_experimental_option("prefs", { \
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 2,
"profile.default_content_setting_values.geolocation": 2,
"profile.default_content_setting_values.notifications": 2
})
driver=webdriver.Chrome(".\chromedriver.exe", options=options)
You can find a couple of relevant detailed discussions in:
Upvotes: 1