title: Check if element is visible and than do the code below - Jasmine JS
body: <p>I've tried to add "if" statement in case of if element is visible in DOM do the code below, else skip of the "if" statement and keep to run the next "it" block.</p>
  
  <p>There an error about:</p>
  
  <blockquote>
    <p>view is not defined at [object Object].</p>
  </blockquote>
  
  <p>Please your help!</p>
  
  <p>The code:</p>
  
  <pre><code>describe('LiveSite Portal - New client send new message', function() {
  
    it('LiveSite - Home Page', function() {
         liveSiteHome();
      });
  
    it('LiveSite - Logged out', function() {
  
      var EC = protractor.ExpectedConditions;
  
      browser.wait(EC.visibilityOf(element(by.binding('new_message'))), 10000);
  
      var forgetMe = expect(element(by.name('new_message')).isPresent()).toBe(true);
  
      if (forgetMe === true) {
         element(by.css("a.forget-me ng-binding")).click();
         browser.driver.sleep(5000);
       }
       else {
          browser.driver.sleep(1000);
       }
  
      });
  
    it('LiveSite - Click on leave a message', function() {
      element(by.xpath("//div[@class='actions-row']//a[.='Leave Your Details']")).click();
      browser.driver.sleep(3000);
  
      expect(element(by.id("new_client_message_message")).isPresent()).toBe(true);
  
      captureScreen("clientNewMessage");
      browser.driver.sleep(3000);
    });
        });
  </code></pre>
  
  <p>This is the element that should be visible:</p>
  
  <pre><code>&lt;div class="row form-control textarea-holder ng-isolate-scope" ng-show="client" vc-animate-active="sendMessageActive"&gt;
        &lt;textarea ng-attr-placeholder="{{&amp;quot;client_zone.navigation.write_your_message&amp;quot; | t}}" ng-attr-rows="{{(show_promotional_link &amp;amp;&amp;amp; actions.length &gt; 3)? 2 : 4}}" ng-model="new_message" vc-focus="sendMessageActive" class="ng-isolate-scope ng-pristine ng-valid" placeholder="Write a new message" rows="4"&gt;&lt;/textarea&gt;
        &lt;div class="cf"&gt;
          &lt;button class="btn btn-account-action btn-with-font-icon icon-env live-button brand-theme ng-binding" ng-bind="&amp;quot;client_zone.navigation.reply&amp;quot; | t" ng-disabled="sending" type="submit"&gt;Send&lt;/button&gt;
          &lt;input class="btn btn-void btn-default" ng-click="$state.go(&amp;quot;main&amp;quot;)" type="button" value="Cancel"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>This is the error from the protractor:</p>
  
  <blockquote>
    <p>Error: Wait timed out after 10009ms at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1630:20 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) at [object Object].promise.Promise.notify_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) at Array.forEach (native) at Object.goog.array.forEach (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) at [object Object].promise.Promise.notifyAll_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16) at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) at runMicrotasksCallback (node.js:337:7) at process._tickCallback (node.js:355:11) From: Task: at [object Object].promise.ControlFlow.wait (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1617:15) at [object Object].webdriver.WebDriver.wait (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:714:21) at [object Object].to.(anonymous function) [as wait] (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\lib\protractor.js:63:25) at [object Object]. (c:\automation\tests\messageNewClient.js:11:13) at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8) at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12) at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) at runMicrotasksCallback (node.js:337:7) From: Task: Asynchronous test function: it() at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33) at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37) at [object Object].jasmine.Block.execute (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17) at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at [object Object].jasmine.Queue.start (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2162:8) at [object Object].jasmine.Spec.execute (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2503:14) at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at onComplete (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2205:18) at [object Object].jasmine.Spec.finish (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2477:5) at [object Object].onComplete (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2504:10)==== async task ==== Error at [object Object]. (c:\automation\tests\messageNewClient.js:7:3) at [object Object].jasmine.Env.describe_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21) at [object Object].jasmine.Env.describe (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15) at describe (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27) at Object. (c:\automation\tests\messageNewClient.js:1:63) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12)</p>
  </blockquote>