forked from caarlos0-graveyard/jProtractor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.js
28 lines (28 loc) · 937 Bytes
/
model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Find elements by model name.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Array.WebElement} The matching input elements.
*/
var findByModel = function(model, using, rootSelector) {
var root = document.querySelector(rootSelector || 'body');
using = using || '[ng-app]';
if (angular.getTestability) {
return angular.getTestability(root).
findModels(using, model, true);
}
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = '[' + prefixes[p] + 'model="' + model + '"]';
var elements = using.querySelectorAll(selector);
if (elements.length) {
return elements;
}
}
};
var using = arguments[0] || document;
var model = arguments[1];
var rootSelector = arguments[2];
return findByModel(model, using, rootSelector);