title: "Stale element reference" error behavior undestanding
body: <p><strong>Code 1:</strong></p>
  
  <pre><code>element(by.id('myButtonId')).click();
  return element(by.id('myValidationSummaryId')).getText().then(function (val) {
      return val;
  });
  </code></pre>
  
  <p>Above code worked fine many times and then it started giving below error </p>
  
  <blockquote>
    <p>"Failed: stale element reference: element is not attached to the page
    document"</p>
  </blockquote>
  
  <p>this id 'myValidationSummaryId' is no where used before, clicking button posts form and success/failure message available from service side in 'myValidationSummaryId'. </p>
  
  <p><strong>Code 2:</strong></p>
  
  <pre><code>return element(by.id('myButtonId')).click().then(function () {
      return element(by.id('myValidationSummaryId')).getText().then(function (val) {
        return val;
      });
  });
  </code></pre>
  
  <p>Fixing code as above fixed original issue and it worked consistently fine many times but later it started failing randomly with original stale element reference error.</p>
  
  <p><strong>Code 3:</strong></p>
  
  <pre><code>return element(by.id('myButtonId')).click().then(function () {
      return element(by.id('myValidationSummaryId')).waitReady().then(function (isReady) {
          if (isReady) {
              return element(by.id('myValidationSummaryId')).getText().then(function (val) {
                  return val;
              });
          } else {
              return 'Failed to check success/failure message';
          }
      });
  });
  </code></pre>
  
  <p>Then I fixed code as above and now it works fine consistently, <a href="https://gist.github.com/elgalu/2939aad2b2e31418c1bb" rel="noreferrer">waitReady</a> function actively wait for an element present and displayed up to specified time.</p>
  
  <p>Shouldn't protractor/WebdriverJS supposed to handle this issues fine natively.</p>
  
  <p>1> could you please explain why Code 1 and Code 2 sometime worked and sometime failed?</p>
  
  <p>2> do you think Code 3 is now fine and expected to work every time?</p>
  
  <p>Element 'myValidationSummaryId' used only once and after click so if pages is not loaded fully and if element is yet not available it should say No Element Found but why stale element reference?
  I have used pageLoadTimeout as 5 minutes and page is loaded in few second. This is non AngularJS application and browser.ignoreSynchronization = true.</p>
  
  <p>everywhere it talked about what code can fix it but not found much on why this behavior and why WebdriverJS itself not able to handle it.</p>