title: Incorrect selenium timeouts
body: <p>I have a code snippet as the following below.  Before I list it I want to let you know that</p>
  
  <p>waitForXPathVisibility (error, seconds, sleep, unit, xpath);</p>
  
  <p>does basically the same as a </p>
  
  <pre><code>WebDriverWait wait = new WebDriverWait(driver, seconds * 1000, sleep * 1000);
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
  </code></pre>
  
  <p>"error" is the error message to print upon timeout.  So I have code</p>
  
  <pre><code>    try {
          waitForXPathVisibility("applicationStatusTab", seconds, 10, TimeUnit.SECONDS, APP_STATUS_TAB_SELECTED_X);
      } catch (Throwable ex) {
          // There seems to be some sort of problem with it not waiting the full amount
          // or throwin an error when there is not, so check for that.
          System.out.println("Timout After: " + new Date() + " ... This may NOT be an actual error:");
          if (!isXPathDisplayed(APP_STATUS_TAB_SELECTED_X)) {
              throw ex;
          }
      }
  </code></pre>
  
  <p>We tell it what time unit to use.  I have specified seconds.</p>
  
  <p>Now the page takes a long time to load.  Without the try, the page would wait maybe 90 seconds or so, and throw a timeout error.  I added the catch and now it catches it and does not give an error, because the xpath is there even though it times out and sait it wasn't:</p>
  
  <pre><code>WARNING: WebDriverException thrown by findElement(By.xpath: 
  //div[@id='pt1:r1']//a[contains(@id,'disAcr') and 
  contains(text(),'Application Status')  and contains(@class,'Selected') ])
  org.openqa.selenium.TimeoutException: timeout
  </code></pre>
  
  <p>However, the isXPathDisplayed() succeeds. (This method basically takes the xpath, does a findElementsBy() and verifies the size is at least one.</p>
  
  <p>What I am wondering is, since the page takes so long to display, somehow when the find operates, it finds the element before the page is displayed in Chrome.  (I have seen that before that the page code is available and ready but sometimes it takes Chrome a while to update the display).</p>
  
  <p>So perhaps the find in the wait() finds the element and exits but since the page is not displayed on the terminal yet, something else may think the element is not there and throw the error.</p>
  
  <p>Does this make sense?  Is there some sort of wait you can issue that will wait until the Chrome display matches the code that Selenium is looking at?  Or am I barking up the wrong tree?</p>
  
  <p>As an aside, even though I catch the error the stack backtrace is still shown, though the catch is successful and the program continues.</p>
  
  <p>Oh, and this is Java with Eclipse and Selenium and Chrome.</p>