Method: Selenium::WebDriver::Element#attribute

Defined in:
lib/selenium/webdriver/common/element.rb

#attribute(name) ⇒ String? Also known as: []

This method attempts to provide the most likely desired current value for the attribute of the element, even when that desired value is actually a JavaScript property. It is implemented with a custom JavaScript atom. To obtain the exact value of the attribute or property, use #dom_attribute or #property methods respectively.

More exactly, this method will return the value of the property with the given name, if it exists. If it does not, then the value of the attribute with the given name is returned. If neither exists, null is returned.

The “style” attribute is converted as best can be to a text representation with a trailing semicolon.

The following are deemed to be “boolean” attributes, and will return either “true” or “false”:

async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate

Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:

When the value of “class” is requested, the “className” property is returned. When the value of “readonly” is requested, the “readOnly” property is returned.

Parameters:

  • name (String)

    attribute name

Returns:

  • (String, nil)

    attribute value

See Also:



126
127
128
# File 'lib/selenium/webdriver/common/element.rb', line 126

def attribute(name)
  bridge.element_attribute self, name
end