8

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

Here is the look of pop up.

here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
daisy
  • 89
  • 1
  • 2
  • 9
  • 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. – Breaks Software Dec 28 '17 at 13:18
  • Possible duplicate of [How can I close the microphone/camera popup in Python / Selenium?](https://stackoverflow.com/questions/47716814/how-can-i-close-the-microphone-camera-popup-in-python-selenium/47717362#47717362) – undetected Selenium Dec 28 '17 at 17:06
  • @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. – daisy Dec 29 '17 at 03:58
  • @DebanjanB Yes, it is simillar to that,Only thing I need to **Allow** the pop up instead of Block. – daisy Dec 29 '17 at 04:01
  • @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. – daisy Dec 29 '17 at 04:41

3 Answers3

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()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 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, } ) – daisy Dec 29 '17 at 06:33
  • Can you update the Question with your current code block and the error stack trace? – undetected Selenium Dec 29 '17 at 06:35
  • 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 Jan 03 '18 at 04:03
  • 1
    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 ;-)** – daisy Jan 24 '18 at 10:27
  • @DebanjanB, Could you plz point me out where I can have the list of experimental options flags? – S.K. Venkat Dec 24 '19 at 10:43
  • @S.K.Venkat Checkout [Chromeoptions and setExperimentalOption code](https://stackoverflow.com/questions/49465124/chromeoptions-and-setexperimentaloption-code/49469595#49469595) – undetected Selenium Dec 24 '19 at 16:08
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);
 }
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"]
    },
)