title: Protractor: wait for an element and then perform action
body: <p>I have written below code to check for locator type and based on whether element is visible or not, I am returning element. I am receiving error on call type(locatorType, value,text) method with appropriate values.</p>
  
  <pre><code>this.type = function(locatorType,value,text){
          this.getElement(locatorType,value).sendKeys(text)
      };
  
  this.getElement = function(locatorType,value){
          if(locatorType=='model'){
              console.log(locatorType)
              console.log(value)
              return this.waiterFunc(element(by.model(value)));
          }
          else if(locatorType=='xPath'){
              return this.waiterFunc(element(by.xPath(value)));
          }
  
          else if(locatorType=='buttonText'){
              return this.waiterFunc(element(by.buttonText(value)));
          }
      };
  
  this.waiterFunc = function(element){
          console.log('In waiterfunc')
          //console.log(element.getText())
          browser.wait(function() {           
              return this.isVisible(element).then(function(){
                  return element;
              })
          })
      };
  
  this.isVisible = function(element){
          return EC.visibilityOf(element);
      };
  </code></pre>
  
  <p>Below is the error being received:
  <a href="https://i.stack.imgur.com/3Oud3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Oud3.png" alt="enter image description here"></a></p>
  
  <p>WebDriver is not able to find the element and perform the actions on it. Please suggest where I am wrong.</p>