title: Selenium PageFactory lazy evaluation StaleElementException
body: <p>I'm doing unit testing on a system using Selenium with a Page Object Model.</p>
  <p>Usually I'm able to figure out a solution to such a problem in relatively short order, but this one is being rather tenacious, so I thought I should just get clarification on the root of the problem rather than write another workaround.</p>
  <p>There is some PageObject class that has an <code>IWebElement</code> property with the necessary <code>FindsBy</code> attribute for locating a element on the page, and a method that uses said property:</p>
  <pre><code>public class Foo : BasePage
  {
      
      ...
      
      [FindsBy(How = How.XPath, Using = &quot;//a[@title='Edit']&quot;)]
      protected IWebElement LinkEdit { get; set; }
      
      ...
      
      public Bar ClickEdit()
      {
          WaitUntilInteractable(LinkEdit);
          LinkEdit.Click();
          
          return new Bar(driver);
      }
      
      ...
      
  }
  </code></pre>
  <p><em>Note that this is the only reference to <code>LinkEdit</code></em></p>
  <p>For clarity, <code>WaitUntilInteractable</code> is defined in <code>BasePage</code> as:</p>
  <pre><code>    protected void WaitUntilInteractable(IWebElement webElement)
      {
          var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
          _ = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(webElement));
      }
  </code></pre>
  <p>My understanding of how the <code>PageFactory</code> works with <code>Selenium</code> is that whenever you reference a <code>IWebElement</code> property of a class, the <code>IWebDriver</code> will then find the element within the page.</p>
  <p>This much is said on this page: <a href="https://github.com/seleniumhq/selenium/wiki/pagefactory" rel="nofollow noreferrer">https://github.com/seleniumhq/selenium/wiki/pagefactory</a></p>
  <blockquote>
  <p>... every time we call a method on the WebElement, the driver will go and find it on the current page again.</p>
  </blockquote>
  <p>Given that knowledge, I don't quite understand how I can run into <code>StaleElementReferenceException</code> when simply referencing one of these properties. Surely either the element cannot be found, in which case a <code>NoSuchElementException</code> will be thrown, or it can be found, in which case it is present on the document, and not &quot;stale&quot;.</p>
  <p>Perhaps I've misunderstood staleness.</p>