Grant access to video and audio in Chrome 48 via Selenium Chromedriver automatically

前端 未结 3 1191
轻奢々
轻奢々 2020-12-22 04:15

I would like to automatically grant access to video and audio in Chrome via Chromedriver capabilities.

Based on this (pretty old) answer I tried the following:

3条回答
  •  一生所求
    2020-12-22 04:48

    Faced similar issue, solved with this:

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

    You can also change default camera using this method:

    Map prefs = new HashMap();
    prefs.put("media.default_video_capture_Device", "\\\\?\\root#media#0002#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global");
    options.setExperimentalOption("prefs", prefs);
    

    Camera code could be obtained from settings window (inspect with dev tools) or from preferences file in Chrome directory.

提交回复
热议问题