I have 2 possible divs.
<div class='a b'></div>
and
<div class='c d'></div>
Is there a way to check if div element has 2 classes a and b?
I use Ruby, Capybara and XPath for selecting elements but css is fine if it could solve problem.
Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names.
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
The is( selector ) method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector. If no element fits, or the selector is not valid, then the response will be 'false'.
This css selector should work in capybara:
page.has_css?('div.a.b')
which will match
<div class="a b">
but not <div class="a">
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