• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

允许Chrome以编程方式使用我的麦克风?

用户头像
it1352
帮助1

问题说明

我目前正在尝试运行一些使用webdriverjs和chromedriver进行的测试,但它们需要麦克风权限.

I am currently trying to run some tests made with webdriverjs and chromedriver but they need microphone permissions.

这是显示的弹出窗口:

我尝试过:

    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();

它也不起作用!我想这不是一个普通的警报.

it did not work either! I guess that this is not an ordinary alert.

有用的链接:

Chrome启动参数列表

Java和ruby的Chrome选项

Chromedriver github

如何通过编程方式授予他们权限?

这附近是否有任何标志或其他方式?

正确答案

#1

每次运行selenium时,都会加载一个新的配置文件,因此在会话之间不会保留对首选项和网站权限所做的更改.要对此进行修改,我们需要告诉selenium要加载哪个配置文件.

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.

第1步.找到您的Chrome偏好设置文件: www.forensicswiki.org/wiki/Google_Chrome#Configuration

Step 1. Find your Chrome preferences file: www.forensicswiki.org/wiki/Google_Chrome#Configuration

步骤2.将文件夹Default复制到某处.我假设它已复制到/some/path/allow-mic/Default.

Step 2. Copy the folder Default somewhere. I will assume it is copied to /some/path/allow-mic/Default.

替代步骤3(这更容易): 复制Default之前,请使用Chrome浏览localhost:1337并将麦克风设置为始终允许.

Alternative Step 3 (this is easier): Before copying Default visit localhost:1337 with Chrome and set mic to always allow.

第3步.编辑allow-mic/Default/Preferences,找到彼此之间的标签"profile""content_settings""exceptions"并添加

Step 3. Edit 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".您应该以如下形式结束:

to "exceptions". You should end up with something like:

...
"profile":{
     ...
     "content_settings": {
         ...
         "exceptions": {
             ...
             "media_stream_mic":{"http://localhost:1337,*":
                                      {"last_used":1470931206,
                                       "setting":1} },
             ...
         },
    },
},
...

第4步: 配置selenium以使用编辑的首选项:

Step 4: Configure 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/来检查是否使用了正确的首选项集(配置文件路径).

You can check that the correct set of preferences (Profile path) are in use by opening chrome://version/.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhecfehj
系列文章
更多 icon
同类精品
更多 icon
继续加载