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

Commit

Permalink
Fix: findElements() and isElementPresent() now work for protractor.By…
Browse files Browse the repository at this point in the history
….input.

Closes #79.
  • Loading branch information
juliemr committed Sep 10, 2013
1 parent 5841af6 commit 806f381
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ clientSideScripts.findRepeaterColumn = function() {
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Array.<Element?} The matching input elements.
*/
clientSideScripts.findInputs = function() {
var using = arguments[0] || document;
var model = arguments[1];
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
var inputs = using.querySelectorAll(selector);
if (inputs.length) {
return inputs;
}
}
};

/**
* Find input elements by model name.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Element} The first matching input element.
*/
clientSideScripts.findInput = function() {
Expand Down Expand Up @@ -701,6 +722,10 @@ ProtractorBy.prototype.input = function(model) {
findOverride: function(driver, using) {
return driver.findElement(
webdriver.By.js(clientSideScripts.findInput), using, model);
},
findArrayOverride: function(driver, using) {
return driver.findElements(
webdriver.By.js(clientSideScripts.findInputs), using, model);
}
};
};
Expand Down
6 changes: 6 additions & 0 deletions spec/findelements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ describe('finding elements', function() {
expect(letterList.getText()).toBe('wxyz');
});

it('should find multiple inputs', function() {
ptor.findElements(protractor.By.input('color')).then(function(arr) {
expect(arr.length).toEqual(3);
});
});

it('should find a repeater by partial match', function() {
var fullMatch = ptor.findElement(
protractor.By.repeater('baz in days | filter:\'T\'').
Expand Down

0 comments on commit 806f381

Please sign in to comment.