Google Groups

HtmlUnitDriver cannot render content if style="display:none"


fritz Feb 9, 2010 2:57 PM
Posted in group: webdriver
Having trouble trying to get the content of an hidden div, if the
content was embedded by a javascript function upon loading the page.
I'm using webdriver-htmlunit version: 0.9.7376. Is this a known issue?
See below for the code.

Sample codes below.

1. save as sample.html
<html>
  <script>
   function populateHiddenHolder() {
     var hidden = document.getElementById("hidden");
     hidden.innerHTML = "content from the hidden div";
   }
  </script>
  <body onload="populateHiddenHolder()">
    <div id="visible">content from the visible div!</div>
    <div id="hidden" style="display:none"></div>
  </body>
</html>

2. Run this WebDriver test.
@Test
public void test() {
 HtmlUnitDriver driver = new HtmlUnitDriver();
 driver.setJavascriptEnabled(true);
 driver.get("file:///home/foconer/personal/sample.html");

 WebElement visible = driver.findElement(By.id("visible"));
 System.out.println("visible:: " + visible.getText());

 RenderedWebElement hidden =
RenderedWebElement)driver.findElement(By.id("hidden"));
 System.out.println("hidden:: " + hidden.getText());
}

3. Result (failed! hidden content is not displaying)

visible:: content from the visible div!
hidden::

Note: this works fine if style="display:none" is removed from the
hidden DIV.