Using capybara, is there a way to get all of the css classes of an element? Looking at the documentation, I do not see any easy way of doing this.
Also, given an element, elem, and a css class, someclass, should elem.has_css?('.someclass')
be equivalent to the jquery $(elem).hasClass('someclass')
?
This particular test is using Selenium, because it involves javascript.
Element#[] looks pretty easy to me:
find('div')[:class]
Also, given an element, elem, and a css class, someclass, should elem.has_css?('.someclass') be equivalent to the jquery $(elem).hasClass('someclass')?
Element#has_css? checks for elements with specified CSS selector within element that method is invoked on. Jquery's hasClass checks if an element has specified class.
Update: Capybara matchers find elements/text within current element. Element#has_css?
checks if an element contains element with specified css selector within it. If you want to check if element exists, use page.has_css?
. Maybe matchers in form expect(page).to have_css('div') would be better for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With