title: WebDriver - wait for element using Java
body: <p>I'm looking for something similar to <code>waitForElementPresent</code> to check whether element is displayed before I click it. I thought this can be done by <code>implicitWait</code>, so I used the following:</p>
  <pre><code>driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  </code></pre>
  <p>and then click by</p>
  <pre><code>driver.findElement(By.id(prop.getProperty(vName))).click();
  </code></pre>
  <p>Unfortunately, sometimes it waits for the element and sometimes not. I looked for a while and found this solution :</p>
  <pre><code>for (int second = 0;; second++) {
      Thread.sleep(sleepTime);
      if (second &gt;= 10)
          fail(&quot;timeout : &quot; + vName);
      try {
          if (driver.findElement(By.id(prop.getProperty(vName))).isDisplayed())
              break;
      } catch (Exception e) {
          writeToExcel(&quot;data.xls&quot;, e.toString(), parameters.currentTestRow, 46);
      }
  }
  driver.findElement(By.id(prop.getProperty(vName))).click();
  </code></pre>
  <p>And it waited all right, but before timing out it had to wait 10 times 5, 50 seconds. A bit much. So I set the implicitly wait to 1sec and all seemed fine until now. Because now some things wait 10s before timeout but some other things time out after 1s.</p>
  <p>How do you cover the waiting for element present/visible in your code? Any hint is appreciable.</p>