Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 806f381

Browse files
committed
Fix: findElements() and isElementPresent() now work for protractor.By.input.
Closes #79.
1 parent 5841af6 commit 806f381

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/protractor.js

+25
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ clientSideScripts.findRepeaterColumn = function() {
212212
* arguments[0] {Element} The scope of the search.
213213
* arguments[1] {string} The model name.
214214
*
215+
* @return {Array.<Element?} The matching input elements.
216+
*/
217+
clientSideScripts.findInputs = function() {
218+
var using = arguments[0] || document;
219+
var model = arguments[1];
220+
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
221+
for (var p = 0; p < prefixes.length; ++p) {
222+
var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
223+
var inputs = using.querySelectorAll(selector);
224+
if (inputs.length) {
225+
return inputs;
226+
}
227+
}
228+
};
229+
230+
/**
231+
* Find input elements by model name.
232+
*
233+
* arguments[0] {Element} The scope of the search.
234+
* arguments[1] {string} The model name.
235+
*
215236
* @return {Element} The first matching input element.
216237
*/
217238
clientSideScripts.findInput = function() {
@@ -701,6 +722,10 @@ ProtractorBy.prototype.input = function(model) {
701722
findOverride: function(driver, using) {
702723
return driver.findElement(
703724
webdriver.By.js(clientSideScripts.findInput), using, model);
725+
},
726+
findArrayOverride: function(driver, using) {
727+
return driver.findElements(
728+
webdriver.By.js(clientSideScripts.findInputs), using, model);
704729
}
705730
};
706731
};

spec/findelements_spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ describe('finding elements', function() {
6565
expect(letterList.getText()).toBe('wxyz');
6666
});
6767

68+
it('should find multiple inputs', function() {
69+
ptor.findElements(protractor.By.input('color')).then(function(arr) {
70+
expect(arr.length).toEqual(3);
71+
});
72+
});
73+
6874
it('should find a repeater by partial match', function() {
6975
var fullMatch = ptor.findElement(
7076
protractor.By.repeater('baz in days | filter:\'T\'').

0 commit comments

Comments
 (0)