Skip to content

Commit 0108b8b

Browse files
Toilallukeis
authored andcommitted
Add textContent attribute support to HtmlUnitDriver
Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
1 parent 65dafcf commit 0108b8b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

common/src/web/simpleTest.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<h1>Heading</h1>
77

88
<p id="oneline">A single line of text</p>
9+
<p id="hiddenline" style="visibility: hidden">A hidden line of text</p>
910

1011
<div id="multiline">
1112
<p>A div containing</p>

java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ public String getAttribute(String name) {
414414
return null;
415415
}
416416

417+
if ("textContent".equalsIgnoreCase(lowerName)) {
418+
return element.getTextContent();
419+
}
420+
417421
if ("value".equals(lowerName)) {
418422
if (element instanceof HtmlTextArea) {
419423
return ((HtmlTextArea) element).getText();

java/client/test/org/openqa/selenium/ElementAttributeTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openqa.selenium.testing.Ignore;
2222
import org.openqa.selenium.testing.JUnit4TestBase;
2323
import org.openqa.selenium.testing.JavascriptEnabled;
24+
import org.openqa.selenium.testing.TestUtilities;
2425

2526
import java.util.List;
2627

@@ -35,6 +36,7 @@
3536
import static org.junit.Assert.assertThat;
3637
import static org.junit.Assert.assertTrue;
3738
import static org.junit.Assert.fail;
39+
import static org.junit.Assume.assumeFalse;
3840
import static org.openqa.selenium.testing.Ignore.Driver.IE;
3941
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
4042

@@ -239,6 +241,18 @@ public void testShouldTreatReadonlyAsAValue() {
239241
assertFalse(readonly.equals(notReadonly));
240242
}
241243

244+
@Test
245+
public void testShouldReturnHiddenTextForTextContentAttribute() {
246+
assumeFalse("IE before 9 doesn't handle textContent attribute", TestUtilities.isOldIe(driver));
247+
248+
driver.get(pages.simpleTestPage);
249+
250+
WebElement element = driver.findElement(By.id("hiddenline"));
251+
String textContent = element.getAttribute("textContent");
252+
253+
assertEquals(textContent, "A hidden line of text");
254+
}
255+
242256
@Test
243257
public void testShouldGetNumericAtribute() {
244258
driver.get(pages.formPage);

0 commit comments

Comments
 (0)