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

Commit bd78dfc

Browse files
committed
fix(protractor): isPresent() should work with out of bounds errors (#3108)
1 parent 6f3a02f commit bd78dfc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/element.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ ElementArrayFinder.prototype.get = function(index) {
243243
i = parentWebElements.length + i;
244244
}
245245
if (i < 0 || i >= parentWebElements.length) {
246-
throw new Error('Index out of bound. Trying to access element at ' +
247-
'index: ' + index + ', but there are only ' +
248-
parentWebElements.length + ' elements that match locator ' +
249-
self.locator_.toString());
246+
throw new webdriver.error.NoSuchElementError('Index out of bound. ' +
247+
'Trying to access element at index: ' + index + ', but there are ' +
248+
'only ' + parentWebElements.length + ' elements that match ' +
249+
'locator ' + self.locator_.toString());
250250
}
251251
return [parentWebElements[i]];
252252
});

spec/basic/elements_spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ describe('ElementFinder', function() {
111111
});
112112
});
113113

114+
it('isPresent() should be friendly with out of bounds error', function () {
115+
browser.get('index.html#/form');
116+
var elementsNotPresent = element.all(by.id('notPresentElementID'));
117+
expect(elementsNotPresent.first().isPresent()).toBe(false);
118+
expect(elementsNotPresent.last().isPresent()).toBe(false);
119+
});
120+
114121
it('isPresent() should not raise error on chained finders', function() {
115122
browser.get('index.html#/form');
116123
var elmFinder = $('.nopenopenope').element(by.binding('greet'));

0 commit comments

Comments
 (0)