From e8bba5006f8e389ab2852225c297873a7939eca8 Mon Sep 17 00:00:00 2001 From: Hank Duan Date: Mon, 16 Jun 2014 14:36:28 -0700 Subject: [PATCH] fix(protractor): throw index-out-of-bounds See https://github.com/angular/protractor/issues/915 - to make error more specific instead of propagate later --- lib/protractor.js | 6 ++++++ 1 file changed, 6 insertions(+) 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);