File tree Expand file tree Collapse file tree
main/java/org/openqa/selenium/htmlunit
test/java/org/openqa/selenium/htmlunit Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )) {
Original file line number Diff line number Diff 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 "
You can’t perform that action at this time.
0 commit comments