Reputation: 917
Is there a way to assert the presence or absence of a css class given I have located the element through another class applied to it?
Here is a sample dom structure -
<div class="large-20 small-20 small-centered large-centered columns">
<div class="row">
<div class="divider1"></div>
<input name="options" type="checkbox" value="2" class="selectable-options grid-value" />
</div>
</div>
where the 'selectable-options' is the class that gets added to the element based on some conditions, and I would like to assert its presence or absence based on the workflow I am testing. I use xpath to reach this element. How do I achieve this?
Upvotes: 0
Views: 1310
Reputation: 968
If you have a css selector of an element and a class you want to check - you can simply combine them into one selector and check if such element exists with casper.test.assertExists
var selector = ".some-element",
className = "class-to-check"
// finding '.some-element.class-to-check'
casper.test.assertExists(selector + "." + className);
Or you can try getElementInfo, it gives more info on target element
If you locate a needed element with css selector, the method returns object with the properties of the node. The class attribute is also available, so you'll be able to inspect a className string
casper.then(function(){
var info = this.getElementInfo("#some-element");
var className = info.attributes["class"] || "";
this.test.assert(className.indexOf("class-to-check") > -1);
});
Upvotes: 4