title: Selenium tests failing in headless mode
body: <p>I have created a Selenium+jUnit test suite that works fine when run through Eclipse but throws exceptions, mostly "Element is not currently visible and so may not be interacted with" exceptions when run in headless manner as a part of teamcity build.</p>
  
  <p>Just to give you an idea of how i'm setup, i have following in the test <code>setUp</code> method:</p>
  
  <pre><code>driver = new FirefoxDriver();
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  driver.manage().deleteAllCookies();
  </code></pre>
  
  <p>Here is the shell script that triggers ant script which in turn runs the test suite.</p>
  
  <pre><code>echo "Executing Xvfb"
  sudo nohup Xvfb :40 -ac -screen 0 1600x900x24 &amp;
  
  echo "Setting the DISPLAY"
  export DISPLAY=:40
  
  echo "Executing the ANT script"
  ant
  </code></pre>
  
  <p>Most errors are related to this piece of code:</p>
  
  <pre><code>....
  
  UtilityMethods.waitUntilElementPresent(driver,By.id("add_section_button"));
  
  Thread.sleep(3000);
  
  driver.findElement(By.id("add_section_button")).click();
  
  ....
  </code></pre>
  
  <p>The <code>waitUntilElementPresent()</code> method is like so:</p>
  
  <pre><code>public static void waitUntilElementPresent(WebDriver driver, By by){
  
      WebDriverWait wait = new WebDriverWait(driver, 20);
  
      wait.until(ExpectedConditions.presenceOfElementLocated(by));
  
  }
  </code></pre>
  
  <p>The above lines generate following error:</p>
  
  <pre><code>Element is not currently visible and so may not be interacted with
  Command duration or timeout: 30.03 seconds
  </code></pre>
  
  <p>Please remember that it only happens in headless mode, this works fine in regular mode. Also, there is no ajax involved and no issue with opacity or visibility either. The 30 second timeout makes sure there is enough time. What could be wrong?</p>
  
  <p>By the way, teamcity runs these tests on a ubuntu agent that has jdk 1.8 and FF 39. I have the same specs on my local machine. </p>