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

3

8

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

Here is the look of pop up.

here

Herr answered 28/12, 2017 at 12:39 Comment(5)
What causes the pop up show? what platform are you on? what kind of application? what have you tried? Please give us some more context so that we have a better idea of the problem.Tafia
Possible duplicate of How can I close the microphone/camera popup in Python / Selenium?Vierno
@BreaksSoftware The site i'm working on,needs my camera and mic. So, i want to allow this authentication pop up. i have tried with alert accept method or via switching window. But it is a authentication browser pop up.So, i don't think so it will help me out.Herr
@DebanjanB Yes, it is simillar to that,Only thing I need to Allow the pop up instead of Block.Herr
@DebanjanB I tried with the code: 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); But it is opening new window and that allow camera method getting passed and failed to the next method.Herr
V
21

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()
Vierno answered 29/12, 2017 at 4:42 Comment(6)
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, } )Herr
Can you update the Question with your current code block and the error stack trace?Vierno
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, })Herr
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 ;-)Herr
@DebanjanB, Could you plz point me out where I can have the list of experimental options flags?Component
@S.K.Venkat Checkout Chromeoptions and setExperimentalOption codeVierno
A
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);
 }
Astrea answered 30/4, 2020 at 16:6 Comment(0)
C
0

This worked for me:

driver.execute_cdp_cmd(
    "Browser.grantPermissions",
    {
        "origin": TARGET_URL    ,   # e.g https://www.google.com
        "permissions": ["geolocation", "audioCapture", "displayCapture", "videoCapture",
                        "videoCapturePanTiltZoom"]
    },
)
Coreen answered 24/7, 2023 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.