我目前正在尝试运行一些使用 webdriverjs 和 chromedriver 进行的测试,但它们需要麦克风权限。
这是显示的弹出窗口:
我努力了:
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();
它也没有用!我想这不是一个普通的警报。
有用的链接:
我如何以编程方式授予他们权限?
有没有标志或其他方式解决这个问题?
原文由 Tiago Bértolo 发布,翻译遵循 CC BY-SA 4.0 许可协议
每次运行 selenium 时都会加载一个新的配置文件,因此您对首选项和网站权限所做的更改不会在会话之间保留。要修改它,我们需要告诉 selenium 要加载哪个配置文件。
第 1 步。找到您的 Chrome 首选项文件: www.forensicswiki.org/wiki/Google_Chrome#Configuration
步骤 2. 将文件夹
Default
复制到某处。我假设它被复制到/some/path/allow-mic/Default
。替代步骤 3(这更容易):在复制之前
Default
localhost:1337
并将麦克风设置为始终允许。Step 3. Edit
allow-mic/Default/Preferences
, find the tags"profile"
,"content_settings"
and"exceptions"
within each other and add至
"exceptions"
。你应该得到类似的结果:第 4 步:配置
selenium
使用已编辑的首选项:您可以通过打开
chrome://version/
检查是否使用了正确的首选项集(配置文件路径)。