Tia*_*olo 12 javascript google-chrome mocha.js selenium-chromedriver selenium-webdriver
我目前正在尝试使用webdriverjs和chromedriver进行一些测试,但他们需要麦克风权限.
这是显示的弹出窗口:
我试过了:
chromedriver.start(['--disable-popup-blocking']);
driver = new Webdriver.Builder()
.withCapabilities(Webdriver.Capabilities.chrome())
.build();
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我也试过了
driver.wait(Until.alertIsPresent(), config.TIMEOUT, 'Alert did not show up');
driver.switchTo().alert().accept();
Run Code Online (Sandbox Code Playgroud)
它也没用!我猜这不是一般的警报.
有用的链接:
我如何以编程方式授予他们权限?
这周围有标志或其他方式吗?
每次运行selenium时都会加载一个新的配置文件,因此您对首选项所做的更改和网站权限不会在会话之间保留.要修改这个,我们需要告诉selenium要加载哪个配置文件.
步骤1.找到您的Chrome偏好设置文件:www.forensicswiki.org/wiki/Google_Chrome#Configuration
步骤2.将文件夹复制到Default某处.我会假设它被复制到/some/path/allow-mic/Default.
替代步骤3(这更容易):在使用Chrome 复制Default访问localhost:1337并将麦克风设置为始终允许之前.
第3步.编辑allow-mic/Default/Preferences,找到标签"profile","content_settings"并"exceptions"在彼此之内添加
"media_stream_mic":{"http://localhost:1337,*":
{"last_used":1470931206,
"setting":1} },
Run Code Online (Sandbox Code Playgroud)
到"exceptions".你应该得到类似的东西:
...
"profile":{
...
"content_settings": {
...
"exceptions": {
...
"media_stream_mic":{"http://localhost:1337,*":
{"last_used":1470931206,
"setting":1} },
...
},
},
},
...
Run Code Online (Sandbox Code Playgroud)
第4步:配置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);
Run Code Online (Sandbox Code Playgroud)
您可以通过打开来检查正在使用的正确的首选项集(配置文件路径)chrome://version/.
小智 7
有点晚了,但在这里为其他人寻找同样的事情,如何做到这一点.
const webdriver = require('selenium-webdriver'), By = webdriver.By, until = webdriver.until,Builder= webdriver.Builder;
var chrome = require('selenium-webdriver/chrome');
var chromeOptions = new chrome.Options()
.addArguments('allow-file-access-from-files')
.addArguments('use-fake-device-for-media-stream')
.addArguments('use-fake-ui-for-media-stream');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions);
driver = driver.build();
Run Code Online (Sandbox Code Playgroud)
对于那些使用 Python 的人,这对我有用:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--use-fake-ui-for-media-stream")
driver = webdriver.Chrome(chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5816 次 |
| 最近记录: |