Another simple solution is to access the HTML attribute you are looking for with []:
find('#my_element')['class']
# => "highlighted clearfix some_other_css_class"
find('a#my_element')['href']
# => "http://example.com
# or in general, find any attribute, even if it does not exist
find('a#my_element')['no_such_attribute']
# => ""
Note that Capybara will automatically try to wait for asynchronous requests to finish, but it may not work in some cases:
- http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
Here is one workaround if you are having trouble with assertions on elements that are updated asynchronously:
- http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara