Reading an element's attributes with Capybara

capybara_element['attribute_name'] Show archive.org snapshot allows accessing an element's attributes in Capybara.

A few examples:

find('#my_element')['class']
# => "first-class second-class"

find('#my_input')['placeholder']
# => "My placeholder value"

find('a#example-link')['href']
# => "http://example.com"

find('#my_element')['missing_attribute']
# => nil
Thomas Klemm Over 9 years ago