0

I've read over this promising thread to try and enable this, but the suggestions aren't working or I'm not following well enough. I tried both methods spelled out in the previous link but no luck. There are no errors in the IDE and Chrome launches fine, but camera and mic still aren't allowed.(details below).

I should also mention that I'm not just trying to make the pop up go away, I need the camera and microphone for testing our application.

I'm using Java 8, Selenium Webdriver 3.8.1, Chrome v.64.

Option 1

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\64.0.3282.140\\default_apps\\1.4_0.crx"));
options.addArguments("start-maximized");

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.content_settings.exceptions.media_stream_camera.'https://<oursite>:443,'.setting","1");
prefs.put("profile.content_settings.exceptions.media_stream_mic.'https://<oursite>:443,'.setting","1");
options.setExperimentalOption("prefs", prefs);

System.setProperty("webdriver.chrome.driver", "C:\\Tools\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);

driver.get(<oursite>);

Option 2

options.addArguments("user-data-dir=C:\\Users\\<user>\\AppData\\Local\\Google\\Chrome\\User Data\\Default");

Thanks for any help offered (especially if it works).

MWAnderson
  • 11
  • 1
  • 6
  • Possible duplicate of [Not able to automate \*\*Allow Camera\*\* pop up](https://stackoverflow.com/questions/48007699/not-able-to-automate-allow-camera-pop-up) – undetected Selenium Feb 14 '18 at 07:24
  • The answer in that thread was to specify a fake camera, but I need to enable a real camera. So I don't think it is a duplicate, though certainly the same root issue. – MWAnderson Feb 14 '18 at 16:12
  • Then again, once I actually used the "fake-ui" argument it actually made my real camera start working... so that appears to solve the problem. – MWAnderson Feb 15 '18 at 16:38

2 Answers2

4

Allowing Camera using add argument use-fake-ui-for-media-stream

ChromeOptions optionsC = new ChromeOptions();
optionsC.addArguments(Arrays.asList("disable-infobars", "ignore-certificate-errors", "start-maximized","use-fake-ui-for-media-stream"));
avojak
  • 2,342
  • 2
  • 26
  • 32
1

So in the end, it was a very simple 'fix' to make it work for me. The "use-fake-ui-for-media-stream" argument turned on the real camera and mic.

ChromeOptions options = new ChromeOptions();
options.addArguments("use-fake-ui-for-media-stream");

System.setProperty("webdriver.chrome.driver", "C:\\Tools\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);

driver.get(<oursite>);
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
MWAnderson
  • 11
  • 1
  • 6