title: How to read text from hidden element with Selenium WebDriver?
body: <p>I'm trying to read the example String <code>1000</code> out of a hidden <code>&lt;div&gt;</code> like this:</p>
  
  <pre><code>&lt;div id="hidden_div" style="visibility:hidden"&gt;1000&lt;/div&gt;
  </code></pre>
  
  <p>I am aware that <code>WebElement.getText()</code> does not work on hidden elements in Selenium 2 (WebDriver), so I searched for solutions (<a href="https://groups.google.com/forum/?fromgroups=#!topic/webdriver/U-TAff1emvo" rel="noreferrer">like this one</a>) and apparently the following code should work:</p>
  
  <pre><code>WebElement hiddenDiv = seleniumDriver.findElement(By.id("hidden_div"));
  String n = hiddenDiv.getText(); // does not work (returns "" as expected)
  String script = "return arguments[0].innerText";
  n = (String) ((JavascriptExecutor) driver).executeScript(script, hiddenDiv);
  </code></pre>
  
  <p>But it doesn't work for me, the variable <code>n</code> always ends up as <code>null</code>. What am I doing wrong?</p>