Checking for the css class of the found element in capybara

Having an element like

My Text

and trying to check if the class is set to “.some-class”

page.find("#some-id").has_css?(".some-class")

does not work in capybara. This is due to the fact that #has_css? checks for
the css being available inside the element not on the element itself. But is
it still easy to check it by accessing the attributes hash.

page.find("#some-id")[:class].include?("some-class")

Works just fine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.