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

573 views
Skip to first unread message

fritz

unread,
Feb 9, 2010, 5:57:26 PM2/9/10
to 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.


Marc Guillemot

unread,
Feb 10, 2010, 3:59:39 AM2/10/10
to webd...@googlegroups.com
Hi,

it's a WebDriver "feature": the FirefoxDriver does exactly the same.

cheers,
Marc.
--
Blog: http://mguillem.wordpress.com

Daniel Wagner-Hall

unread,
Feb 10, 2010, 7:51:48 AM2/10/10
to webd...@googlegroups.com
See http://code.google.com/p/selenium/issues/detail?id=371#c4

> --
> You received this message because you are subscribed to the Google Groups
> "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to
> webdriver+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/webdriver?hl=en.
>
>

Simon Stewart

unread,
Feb 13, 2010, 4:31:37 PM2/13/10
to webd...@googlegroups.com
As does Selenium.

Simon

Reply all
Reply to author
Forward
0 new messages