我如何让Chrome以编程方式使用我的麦克风? [英] How do i allow Chrome to use my microphone programatically?
问题描述
我目前正在尝试使用webdriverjs和chromedriver进行一些测试,但它们需要麦克风权限。
这是显示的弹出窗口:
我曾尝试过:
chromedriver.start([' - disable-popup-blocking']);
driver = new Webdriver.Builder()
.withCapabilities(Webdriver.Capabilities.chrome())
.build();
但没有用。
我也试过
$ $ p $ driver.wait(Until.alertIsPresent(),config.TIMEOUT,'Alert did not show up') ;
driver.switchTo()。alert()。accept();
它也行不通!我想这不是一个普通的警报。
有用的链接:
我如何以编程方式授予他们权限? 是否有任何标记或其他方法? 每次运行selenium时都会加载一个新配置文件,因此您不会在会话之间保留对首选项和网站权限所做的更改。要修正这个问题,我们需要告诉Selenium加载哪个配置文件。第1步。找到您的Chrome首选项文件: www.forensicswiki.org/wiki/Google_Chrome#Configuration 第2步。复制文件夹 这很容易): 步骤3.编辑 到 第4步: 您可以通过打开<$ c来检查正确的一组首选项(配置文件路径) $ c> chrome:// version / 。 I am currently trying to run some tests made with webdriverjs and chromedriver but they need microphone permissions. This is the popup that shows up: I have tried: but it didn't work. I also tried it did not work either! I guess that this is not an ordinary alert. Useful links: Chrome options for java and ruby How do i give them permissions programatically? Is there any flag or some other way around this? A fresh profile is loaded each time you run selenium, hence changes you make to the preferences and website permissions are not preserved between sessions. To amend this we need to tell selenium which profile to load. Step 1. Find your Chrome preferences file: www.forensicswiki.org/wiki/Google_Chrome#Configuration Step 2. Copy the folder Alternative Step 3 (this is easier):
Before copying Step 3. Edit to Step 4:
Configure You can check that the correct set of preferences (Profile path) are in use by opening 这篇关于我如何让Chrome以编程方式使用我的麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
默认
某处。我会假设它被复制到 / some / path / allow-mic / Default
。
复制之前默认
使用Chrome访问 localhost:1337
并将麦克风设置为始终允许。
allow-mic / Default / Preferences
,找到标签 profile
,content_settings
和exceptions
/ p>
media_stream_mic:{http:// localhost:1337,*:
{last_used:1470931206 ,
setting:1}},
例外
。您最终应该得到如下结果:
...
profile:{
.. 。
content_settings:{
...
例外:{
...
media_stream_mic:{http:// localhost:1337 ,*:
{last_used:1470931206,
setting:1}},
...
},
},
},
...
配置 selenium
以使用编辑后的首选项:
var chromedriver = require('chromedriver');
var Webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver / chrome');
var opts = new chrome.Options();
opts.addArguments(user-data-dir = / some / path / allow-camera);
var driver = new chrome.Driver(opts);
chromedriver.start(['--disable-popup-blocking']);
driver = new Webdriver.Builder()
.withCapabilities(Webdriver.Capabilities.chrome())
.build();
driver.wait(Until.alertIsPresent(), config.TIMEOUT, 'Alert did not show up');
driver.switchTo().alert().accept();
Default
somewhere. I will assume it is copied to /some/path/allow-mic/Default
.Default
visit localhost:1337
with Chrome and set mic to always allow.allow-mic/Default/Preferences
, find the tags "profile"
, "content_settings"
and "exceptions"
within each other and add"media_stream_mic":{"http://localhost:1337,*":
{"last_used":1470931206,
"setting":1} },
"exceptions"
. You should end up with something like:...
"profile":{
...
"content_settings": {
...
"exceptions": {
...
"media_stream_mic":{"http://localhost:1337,*":
{"last_used":1470931206,
"setting":1} },
...
},
},
},
...
selenium
to use the edited preferences:var chromedriver = require('chromedriver');
var Webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var opts = new chrome.Options();
opts.addArguments("user-data-dir=/some/path/allow-camera");
var driver = new chrome.Driver(opts);
chrome://version/
.