title: Protractor - Test is failed when element is not visible and doesn't perform the "else" condition
body: <p>I've tried to run a flow with "if/else statement" that depend on if some element is visible or not.</p>
  
  <p>But in the case this element is not visible it doesn't run into the "else condition" and all the test case is failed.</p>
  
  <p>Please your help! thanks.</p>
  
  <p><strong>The test case:</strong></p>
  
  <pre><code>   it('New Client LiveSite - Payments - Perform a payment by PayPal', function () {
     browser.wait(EC.visibilityOf(element(by.binding("buttonText"))), 30000);
      element(by.binding("buttonText")).click();
  
              var mainWindow;
              browser.getAllWindowHandles().then(
                  function(handles) {
                      mainWindow = handles[0]; //at this point there should be only 1 window
                  }
              );
  
              browser.getAllWindowHandles().then(function (handles) {    
                 handles.forEach(function(handle) {
                   if (handle !== mainWindow) {
                      browser.switchTo().window(handle)
                      var loadLogin = element(by.id("loadLogin"));
                      element.all(by.id('loadLogin')).then(function(){ 
                          expect(browser.driver.getCurrentUrl()).toContain('www.paypal.com');
                          browser.sleep(10000); 
  
                      loadLogin.isDisplayed().then(function(result) {
                            if (result === true) {
                                  loadLogin.click();
                                  browser.driver.sleep(3000);
                                  element(by.id("login_email")).sendKeys("username");
                                  element(by.id("login_password")).sendKeys("pass");
                                  browser.driver.sleep(1000);
                                  element(by.id("submitLogin")).click();
                                  browser.driver.sleep(5000);
                                  element(by.id("submit.x")).click();
                                  browser.driver.sleep(10000);
                                  console.log("-=-=- first condition - I'm not logged-in -=-=-");
                              } else {
                                   browser.driver.sleep(3000);
                                   element(by.id("login_email")).clear();
                                   browser.driver.sleep(1000);
                                   element(by.id("login_email")).sendKeys("username");
                                   element(by.id("login_password")).sendKeys("pass");
                                   browser.driver.sleep(1000);
                                   element(by.id("submitLogin")).click();
                                   browser.driver.sleep(10000);
                                   element(by.id("submit.x")).click();
                                   browser.driver.sleep(10000);
                                   console.log("-=-=- second condition - I'm already logged-in -=-=-")
                              }
                          });
                      });
                   }
              });
          });
  
              browser.getAllWindowHandles().then(function (handles) {
                  browser.switchTo().window(handles[0]);
              });
  
  });
  </code></pre>
  
  <p><strong>The error: [edited]</strong></p>
  
  <pre><code> New Client LiveSite - Payments - Perform a payment by PayPal - fail
  Error occurred in loadLogin.isDisplayed: { [NoSuchElementError: No element found
   using locator: By.id("loadLogin")]
    code: 7,
    state: 'no such element',
    message: 'No element found using locator: By.id("loadLogin")',
    name: 'NoSuchElementError',
    stack: 'NoSuchElementError: No element found using locator: By.id("loadLogin")
  \n    at new bot.Error (C:\\Users\\idan\\AppData\\Roaming\\npm\\node_modules\\pr
  otractor\\node_modules\\selenium-webdriver\\lib\\atoms\\error.js:113:18)\n    at
   C:\\Users\\idan\\AppData\\Roaming\\npm\\node_modules\\protractor\\lib\\element.
  js:706:15\n    at [object Object].promise.ControlFlow.runInFrame_ (C:\\Users\\id
  an\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webd
  river\\lib\\webdriver\\promise.js:1877:20)\n    at [object Object].promise.Callb
  ack_.goog.defineClass.notify (C:\\Users\\idan\\AppData\\Roaming\\npm\\node_modul
  es\\protractor\\node_modules\\selenium-webdriver\\lib\\webdriver\\promise.js:246
  4:25)\n    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)\n    at Array.forEach (native)\n    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)\n    at [
  object Object].promise.Promise.notifyAll_ (C:\\Users\\idan\\AppData\\Roaming\\np
  m\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\webdriver\\p
  romise.js:552:16)\n    at goog.async.run.processWorkQueue (C:\\Users\\idan\\AppD
  ata\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\l
  ib\\goog\\async\\run.js:125:21)\n    at runMicrotasksCallback (node.js:337:7)\nE
  rror\n    at [object Object].ElementArrayFinder.applyAction_ (C:\\Users\\idan\\A
  ppData\\Roaming\\npm\\node_modules\\protractor\\lib\\element.js:403:21)\n    at
  [object Object].self.(anonymous function) [as isDisplayed] (C:\\Users\\idan\\App
  Data\\Roaming\\npm\\node_modules\\protractor\\lib\\element.js:76:19)\n    at [ob
  ject Object].self.(anonymous function) [as isDisplayed] (C:\\Users\\idan\\AppDat
  a\\Roaming\\npm\\node_modules\\protractor\\lib\\element.js:733:11)\n    at c:\\a
  utomation\\tests\\paymentsNewClient.js:71:39\n    at [object Object].promise.Con
  trolFlow.runInFrame_ (C:\\Users\\idan\\AppData\\Roaming\\npm\\node_modules\\prot
  ractor\\node_modules\\selenium-webdriver\\lib\\webdriver\\promise.js:1877:20)\n
     at [object Object].promise.Callback_.goog.defineClass.notify (C:\\Users\\idan
  \\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdri
  ver\\lib\\webdriver\\promise.js:2464:25)\n    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)\n    at Array.f
  orEach (native)\n    at Object.goog.array.forEach (C:\\Users\\idan\\AppData\\Roa
  ming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\goog
  \\array\\array.js:203:43)\n    at [object Object].promise.Promise.notifyAll_ (C:
  \\Users\\idan\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\se
  lenium-webdriver\\lib\\webdriver\\promise.js:552:16)' }
  </code></pre>