lib/protractor.js
function() {
      return elementArrayFinder.getWebElements().then(function(webElements) {
        if (webElements.length === 0) {
          throw new webdriver.error.Error(
              webdriver.error.ErrorCode.NO_SUCH_ELEMENT,
              'No element found using locator: ' +
                  elementArrayFinder.locator_.toString());
        } else {
          if (webElements.length > 1) {
            console.log('warning: more than one element found for locator ' +
                elementArrayFinder.locator_.toString() +
                ' - you may need to be more specific');
          }
          return [webElements[0]];
        }
      });
    }
function() {
      return elementArrayFinder.getWebElements().then(function(webElements) {
        if (webElements.length === 0) {
          throw new webdriver.error.Error(
              webdriver.error.ErrorCode.NO_SUCH_ELEMENT,
              'No element found using locator: ' +
                  elementArrayFinder.locator_.toString());
        } else {
          if (webElements.length > 1) {
            console.log('warning: more than one element found for locator ' +
                elementArrayFinder.locator_.toString() +
                ' - you may need to be more specific');
          }
          return [webElements[0]];
        }
      });
    }
function ( ) { return elementArrayFinder . getWebElements ( ) . then ( function ( webElements ) { if ( webElements . length === 0 ) { throw new webdriver . error . Error ( webdriver . error . ErrorCode . NO_SUCH_ELEMENT , 'No element found using locator: ' + elementArrayFinder . locator_ . toString ( ) ) ; } else { if ( webElements . length > 1 ) { console . log ( 'warning: more than one element found for locator ' + elementArrayFinder . locator_ . toString ( ) + ' - you may need to be more specific' ) ; } return [ webElements [ 0 ] ] ; } } ) ; }
This filter verifies that there is only 1 element returned by the elementArrayFinder. It will warn if there are more than 1 element and throw an error if there are no elements.
This filter verifies that there is only 1 element returned by the elementArrayFinder . It will warn if there are more than 1 element and throw an error if there are no elements .