title: Selenium+Ruby issue because of page reload
body: <p>I've the following code:</p>
  
  <pre><code>wait.until {driver.find_element(:xpath, "//input[@class='btn btn-success Testserver']")}
  element = driver.find_element(:xpath, "//input[@class='btn btn-success Testserver']")
  element.click
  wait.until {driver.find_element(:xpath, "//input[@class='btn btn-success Testserver2']")}
  element = driver.find_element(:xpath, "//input[@class='btn btn-success Testserver2']")
  element.click
  </code></pre>
  
  <p>My problem is the 3rd and the 4th line. When selenium clicks the first element, it causes a page reload. The problem is that the 4th line (the wait.until) finds the element BEFORE the reload is executed. So what happens? Selenium thinks the element is already loaded, it try to continue and after that the pages reload and selenium throw out an error, cause it can't find the element.</p>
  
  <pre><code>Selenium::WebDriver::Error::StaleElementReferenceError: The element reference is stale. Either the element is no longer attached to the DOM or the page has been refreshed.
  </code></pre>
  
  <p>What can i do? The code works fine when i put a sleep between this lines, but i don't wan't to use sleep cause of bad practice. Is there another way?</p>
  
  <p>Thanks for your help!</p>