通过Selenium Chromedriver自动在Chrome 48中授予对视频和音频的访问权限 [英] Grant access to video and audio in Chrome 48 via Selenium Chromedriver automatically
本文介绍了通过Selenium Chromedriver自动在Chrome 48中授予对视频和音频的访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Chromedriver功能在Chrome中自动授予对视频和音频的访问权限。 基于这个(漂亮的老)答案我试过以下内容:
DesiredCapabilities capabilities = DesiredCapabilities.chrome ();
ChromeOptions选项=新ChromeOptions();
地图< String,Object> prefs = new HashMap<>();
//这个chrome仍然要求权限
prefs.put(profile.managed_default_content_settings.media_stream,1);
prefs.put(profile.managed_default_content_settings.media_stream_camera,1);
prefs.put(profile.managed_default_content_settings.media_stream_mic,1);
//这会阻止chrome启动
prefs.put(profile.content_settings.exceptions.media_stream_mic.https://*,*.setting,1);
prefs.put(profile.content_settings.exceptions.media_stream_mic.https://*,*.last_used,1);
prefs.put(profile.content_settings.exceptions.media_stream_camera.https://*,*.setting,1);
prefs.put(profile.content_settings.exceptions.media_stream_camera.https://*,*.last_used,1);
//并且这可以防止chrome开始以及
prefs.put(profile.content_settings.pattern_pairs.https://*,*.media_stream.video,Allow) ;
prefs.put(profile.content_settings.pattern_pairs.https://*,*.media_stream.audio,Allow);
options.setExperimentalOption(prefs,prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
有关如何正确授予权限的想法?
解决方案
面临类似问题,解决此问题:
ChromeOptions options = new ChromeOptions ();
options.addArguments( - use-fake-ui-for-media-stream = 1);
驱动程序=新的ChromeDriver(选项);
您也可以使用此方法更改默认相机:
映射< String,Object> prefs = new HashMap< String,Object>();
prefs.put(media.default_video_capture_Device,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' );
options.setExperimentalOption(prefs,prefs);
相机代码可以从设置窗口(使用开发工具进行检查)或Chrome目录中的首选项文件。
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:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
// with this chrome still asks for permission
prefs.put("profile.managed_default_content_settings.media_stream", 1);
prefs.put("profile.managed_default_content_settings.media_stream_camera", 1);
prefs.put("profile.managed_default_content_settings.media_stream_mic", 1);
// and this prevents chrome from starting
prefs.put("profile.content_settings.exceptions.media_stream_mic.https://*,*.setting", 1);
prefs.put("profile.content_settings.exceptions.media_stream_mic.https://*,*.last_used", 1);
prefs.put("profile.content_settings.exceptions.media_stream_camera.https://*,*.setting", 1);
prefs.put("profile.content_settings.exceptions.media_stream_camera.https://*,*.last_used", 1);
// and this prevents chrome from starting as well
prefs.put("profile.content_settings.pattern_pairs.https://*,*.media_stream.video", "Allow");
prefs.put("profile.content_settings.pattern_pairs.https://*,*.media_stream.audio", "Allow");
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Any ideas on how to grant permissions correctly?
解决方案
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<String, Object> prefs = new HashMap<String, Object>();
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.
这篇关于通过Selenium Chromedriver自动在Chrome 48中授予对视频和音频的访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文