diff --git a/lib/protractor.js b/lib/protractor.js index 66c2d9a0e..f43dbf2a0 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -584,6 +584,12 @@ var buildElementHelper = function(ptor) { // -1 is special and means last index = arr.length - 1; } + + if (index >= arr.length) { + throw new Error('Index out of bound. Trying to access index:' + index + + ', but locator: ' + locatorMessage + ' only has ' + + arr.length + ' elements'); + } return arr[index]; }); return new webdriver.WebElement(ptor.driver, id);