Skip to content

Commit fbc2bca

Browse files
committed
more unit tests (using #137 as inspiration) and fix for #140
1 parent 3c77974 commit fbc2bca

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ public String getAttribute(final String name) {
336336
}
337337

338338
final String attributeValue = element_.getAttribute(name);
339-
return attributeValue == null ? "" : attributeValue;
339+
if (ATTRIBUTE_NOT_DEFINED == attributeValue) {
340+
return null;
341+
}
342+
return attributeValue;
340343
}
341344

342345
if ("disabled".equals(lowerName)) {

src/test/java/org/openqa/selenium/htmlunit/HtmlUnitWebElementAttributeTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,46 @@ public void valueOption() throws Exception {
114114
assertEquals("4", elem.getAttribute("value"));
115115
}
116116

117+
@Test
118+
public void valueDiv() throws Exception {
119+
final String html = "<html>\n"
120+
+ "<head>\n"
121+
+ "</head>\n"
122+
+ "<body>\n"
123+
+ " <div id='d1'>1</div>\n"
124+
+ " <div id='d2' value='two'>2</div>\n"
125+
+ "</body>\n"
126+
+ "</html>\n";
127+
128+
final WebDriver driver = loadPage2(html);
129+
130+
WebElement elem = driver.findElement(By.id("d1"));
131+
assertNull(elem.getAttribute("value"));
132+
133+
elem = driver.findElement(By.id("d2"));
134+
assertEquals("two", elem.getAttribute("value"));
135+
}
136+
137+
@Test
138+
public void valueP() throws Exception {
139+
final String html = "<html>\n"
140+
+ "<head>\n"
141+
+ "</head>\n"
142+
+ "<body>\n"
143+
+ " <p id='d1'>1</p>\n"
144+
+ " <p id='d2' value='two'>2</p>\n"
145+
+ "</body>\n"
146+
+ "</html>\n";
147+
148+
final WebDriver driver = loadPage2(html);
149+
150+
WebElement elem = driver.findElement(By.id("d1"));
151+
assertNull(elem.getAttribute("value"));
152+
153+
elem = driver.findElement(By.id("d2"));
154+
assertEquals("two", elem.getAttribute("value"));
155+
}
156+
117157
@Test
118158
public void checkbox() throws Exception {
119159
final String html = "<html>\n"

0 commit comments

Comments
 (0)