title: Waiting for all actions to be executed after clicking a button in selenium
body: <p>i'm sorry if it's been answered before but i really couldn't find a good solution to my problem</p>
  
  <p>I have an email input field and i want to check that when you input an invalid email an error message appears.
  my code looks somthing like this:</p>
  
  <pre><code>private void LoadElements()
  {
       Email = driver.FindElement(By.Id("MainContent_Email"));
       SaveButton = driver.FindElement(By.Id("MainContent_SaveButton"));
       ErrorMessage = driver.FindElement(By.Id("MainContent_PersDetsError"));
  }
  public void test()
  {
       //Email, SaveButton &amp; Error are IWebElement
       LoadElements();
       Email.Clear();
       Email.SendKeys(emailString);
       SaveButton.Click();
       // Avoid stale element exception on refresh after a successful save:
       LoadElements();
       Assert.IsTrue(ErrorMessage.Displayed);
  }
  </code></pre>
  
  <p>My problem is that when i try to purposly fail the test (input a valid email), some of the time I still get a stale element exception. I presume this happens becuse LoadElements() loads the web elements too quickly.</p>
  
  <p>My question is this: is there a way to wait for the page to fully load before executing any commends?</p>
  
  <p>PS I tried the following code and it didn't work for me</p>
  
  <pre><code>IWait&lt;IWebDriver&gt; wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
  
   wait.Until(driver1 =&gt; ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
  </code></pre>