Reading an element's attributes with Capybara

Updated . Posted . Visible to the public.

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
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2015-01-07 10:43)