title: WebDriver executing javascript strange behaviour
body: <p>I'm using Webdriver through JBehave-Web distribution (3.3.4) to test an application and I'm facing something quite strange:</p>
  
  <p>I'm trying to interact with a modalPanel from Richfaces, which gave me a lot of problems because it throws ElementNotVisibleException. I solved it by using javascript:</p>
  
  <p>This is the code in my page object which extends from org.jbehave.web.selenium.WebDriverPage</p>
  
  <pre><code>protected void changeModalPanelInputText(String elementId, String textToEnter){
      makeNonLazy();
      JavascriptExecutor je = (JavascriptExecutor) webDriver();
      String script ="document.getElementById('" + elementId + "').value = '" + textToEnter + "';";
      je.executeScript(script);
  }
  </code></pre>
  
  <p>The strange behaviour is that if I execute the test normally, it does nothing, but if I put a breakpoint in the last line (in Eclipse), select the line and execute from Eclipse (Ctrl + U), I can see the changes in the browser.</p>
  
  <p>I checked the JavascriptExecutor and the WebDriver classes to see if there was any kind of buffering, but I couldn't find anything. Any ideas?</p>
  
  <p><strong>EDIT</strong>
  I found out that putting the thread to sleep for 1 second it makes it work, so it looks some kind of race condition, but cannot find out why...</p>
  
  <p>This is the way it "works", but I'm not very happy about it:</p>
  
  <pre><code>protected void changeModalPanelInputText(String elementId, String textToEnter){
      String script ="document.getElementById('" + elementId + "').value = '" + textToEnter + "';";
      executeJavascript(script);
  }
  
      private void executeJavascript(String script){
      makeNonLazy();
      JavascriptExecutor je = (JavascriptExecutor) webDriver();
      try {
          Thread.sleep(1500);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      je.executeScript(script);       
  }
  </code></pre>
  
  <p>Putting the wait in any other position doesn't work either...</p>