How to allow or deny notification geo-location microphone camera pop up

10,548

Solution 1

To Allow or Block the notification of Microphone, Camera, GeoLocation, Notification access using Selenium you have to use ChromeOptions Class as follows :

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

opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block
opt.add_experimental_option("prefs", { \
    "profile.default_content_setting_values.media_stream_mic": 1, 
    "profile.default_content_setting_values.media_stream_camera": 1,
    "profile.default_content_setting_values.geolocation": 1, 
    "profile.default_content_setting_values.notifications": 1 
  })

driver = webdriver.Chrome(chrome_options=opt, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

Solution 2

This java code helped me

public WebDriver initWebDriver() {
     ChromeOptions options = new ChromeOptions();
     options.addArguments("use-fake-device-for-media-stream");
     options.addArguments("use-fake-ui-for-media-stream");
     prefs = new HashMap<String, Object>();
     prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
     prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
     prefs.put("profile.default_content_setting_values.geolocation", 1);
     prefs.put("profile.default_content_setting_values.notifications", 1);
     options.setExperimentalOption("prefs", prefs);
     System.setProperty(CHROME_DRIVER, DRIVER_PATH);
     return new ChromeDriver(options);
 }
Share:
10,548
daisy
Author by

daisy

Updated on July 29, 2022

Comments

  • daisy
    daisy almost 2 years

    I'm not able to click on Allow button of access camera authentication pop up.

    Here is the look of pop up.

    here

  • daisy
    daisy over 6 years
    I'm facing some error on below line using this code.It would be appreciated if you can help me : options.addArguments ( "prefs", { "profile.default_content_setting_values.media_stream_mic":1, "profile.default_content_setting_values.media_stream_camera"‌​:1, } )
  • undetected Selenium
    undetected Selenium over 6 years
    Can you update the Question with your current code block and the error stack trace?
  • daisy
    daisy over 6 years
    I'm having syntax error as: Multiple markers at this line - Syntax error on token ":", invalid AssignmentOperator - The left-hand side of an assignment must be a variable Over below line code: opt.add_experimental_option("prefs", { \ "profile.default_content_setting_values.media_stream_mic": 1, "profile.default_content_setting_values.media_stream_camera"‌​: 1, })
  • daisy
    daisy over 6 years
    ChromeOptions options = new ChromeOptions(); options.addArguments("allow-file-access-from-files"); options.addArguments("use-fake-device-for-media-stream"); options.addArguments("use-fake-ui-for-media-stream"); WebDriver driver = new ChromeDriver(options); This Method helped me ;-)
  • S.K. Venkat
    S.K. Venkat over 4 years
    @DebanjanB, Could you plz point me out where I can have the list of experimental options flags?
  • undetected Selenium
    undetected Selenium over 4 years