lib/commands/element.js
function (selector, expected, hash) {
    this.actionQueue.push(this.webdriverClient.elements.bind(this.webdriverClient, selector));
    this.actionQueue.push(function (result) {
      var deferred = Q.defer();
      var res = JSON.parse(result);
      var resLength = res.value.length;
      var curLength = 0;
      var visibleElement = [];

      res.value.forEach(function (element) {
        var fakeResponse = JSON.stringify({sessionId: res.sessionId, status: 0, value: element.ELEMENT});
        this.webdriverClient.options.id = element.ELEMENT;
        this.webdriverClient.displayed.bind(this.webdriverClient, selector)(fakeResponse).then(function (visRes) {
          curLength++;
          if (JSON.parse(visRes).value === true) {
            visibleElement.push(element);
          }
          if (curLength === resLength) {
            deferred.resolve(JSON.stringify({sessionId: res.sessionId, status: 0, value: visibleElement}));
          }
        });
      }.bind(this));

      return deferred.promise;
    }.bind(this));
    this.actionQueue.push(this._getNumberOfVisibleElementsCb.bind(this, selector, hash, expected));
    return this;
  }
function (selector, expected, hash) {
    this.actionQueue.push(this.webdriverClient.elements.bind(this.webdriverClient, selector));
    this.actionQueue.push(function (result) {
      var deferred = Q.defer();
      var res = JSON.parse(result);
      var resLength = res.value.length;
      var curLength = 0;
      var visibleElement = [];

      res.value.forEach(function (element) {
        var fakeResponse = JSON.stringify({sessionId: res.sessionId, status: 0, value: element.ELEMENT});
        this.webdriverClient.options.id = element.ELEMENT;
        this.webdriverClient.displayed.bind(this.webdriverClient, selector)(fakeResponse).then(function (visRes) {
          curLength++;
          if (JSON.parse(visRes).value === true) {
            visibleElement.push(element);
          }
          if (curLength === resLength) {
            deferred.resolve(JSON.stringify({sessionId: res.sessionId, status: 0, value: visibleElement}));
          }
        });
      }.bind(this));

      return deferred.promise;
    }.bind(this));
    this.actionQueue.push(this._getNumberOfVisibleElementsCb.bind(this, selector, hash, expected));
    return this;
  }
function ( selector , expected , hash ) { this . actionQueue . push ( this . webdriverClient . elements . bind ( this . webdriverClient , selector ) ) ; this . actionQueue . push ( function ( result ) { var deferred = Q . defer ( ) ; var res = JSON . parse ( result ) ; var resLength = res . value . length ; var curLength = 0 ; var visibleElement = [ ] ; res . value . forEach ( function ( element ) { var fakeResponse = JSON . stringify ( { sessionId : res . sessionId , status : 0 , value : element . ELEMENT } ) ; this . webdriverClient . options . id = element . ELEMENT ; this . webdriverClient . displayed . bind ( this . webdriverClient , selector ) ( fakeResponse ) . then ( function ( visRes ) { curLength ++ ; if ( JSON . parse ( visRes ) . value === true ) { visibleElement . push ( element ) ; } if ( curLength === resLength ) { deferred . resolve ( JSON . stringify ( { sessionId : res . sessionId , status : 0 , value : visibleElement } ) ) ; } } ) ; } . bind ( this ) ) ; return deferred . promise ; } . bind ( this ) ) ; this . actionQueue . push ( this . _getNumberOfVisibleElementsCb . bind ( this , selector , hash , expected ) ) ; return this ; }
Returns the number of visible elements matched by the selector

@method getNumberOfVisibleElements
@param {string} selector Selector expression to find the elements
@param {integer} expected Expected number of matched elements
@param {string} uuid Unique hash of that fn call
@chainable
Returns the number of visible elements matched by the selector