Skip to content

Commit b8fd774

Browse files
juangjTikhomirovSergey
authored andcommitted
Implement getAttribute for W3C-compliant remote ends.
Fix docs for WebElement.getAttribute to attempt to better reflect reality. This shim is supposed to replicate the OSS behavior, but in terms of W3C-compliant "Get Element Attribute" and "Get Element Property" commands. (See #2301.)
1 parent 5bff91f commit b8fd774

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/main/java/org/openqa/selenium/WebElement.java

+24-15
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,37 @@ public interface WebElement extends SearchContext, TakesScreenshot {
8787
String getTagName();
8888

8989
/**
90-
* Get the value of a the given attribute of the element. Will return the current value, even if
91-
* this has been modified after the page has been loaded. More exactly, this method will return
92-
* the value of the given attribute, unless that attribute is not present, in which case the value
93-
* of the property with the same name is returned (for example for the "value" property of a
94-
* textarea element). If neither value is set, null is returned. The "style" attribute is
95-
* converted as best can be to a text representation with a trailing semi-colon. The following are
96-
* deemed to be "boolean" attributes, and will return either "true" or null:
97-
* <p>
98-
* async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
90+
* Get the value of the given attribute of the element. Will return the current value, even if
91+
* this has been modified after the page has been loaded.
92+
*
93+
* <p>More exactly, this method will return the value of the property with the given name, if it
94+
* exists. If it does not, then the value of the attribute with the given name is returned. If
95+
* neither exists, null is returned.
96+
*
97+
* <p>The "style" attribute is converted as best can be to a text representation with a trailing
98+
* semi-colon.
99+
*
100+
* <p>The following are deemed to be "boolean" attributes, and will return either "true" or null:
101+
*
102+
* <p>async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
99103
* defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
100104
* iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade,
101105
* novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless,
102-
* seeking, selected, spellcheck, truespeed, willvalidate
103-
* <p>
104-
* Finally, the following commonly mis-capitalized attribute/property names are evaluated as
106+
* seeking, selected, truespeed, willvalidate
107+
*
108+
* <p>Finally, the following commonly mis-capitalized attribute/property names are evaluated as
105109
* expected:
106-
* <p>
110+
*
107111
* <ul>
108-
* <li>"class"
109-
* <li>"readonly"
112+
* <li>If the given name is "class", the "className" property is returned.
113+
* <li>If the given name is "readonly", the "readOnly" property is returned.
110114
* </ul>
111115
*
116+
* <i>Note:</i> The reason for this behavior is that users frequently confuse attributes and
117+
* properties. If you need to do something more precise, e.g., refer to an attribute even when a
118+
* property of the same name exists, then you should evaluate Javascript to obtain the result
119+
* you desire.
120+
*
112121
* @param name The name of the attribute.
113122
* @return The attribute/property's current value or null if the value is not set.
114123
*/

0 commit comments

Comments
 (0)