I want to:
- Find the first <li> element that contains the specified classes
- Click it
- Verify that it subsequently also has a "checked" class
Take the following command that I've created in a Page object:
selectCar: function(props)
var selector = 'li';
selector += (props.indexOf('hybrid') > -1) ? '.hybrid-1' : '.hybrid-0';
this.click(selector);
this.api.element('css selector', selector, function(el) {
browser.elementIdAttribute(el.value.ELEMENT, 'class', function(result) {
console.log(result);
});
});
return this;
}
Given that my css selector is going to look like, say, "li.hybrid-1" -
what, exactly, is click() doing? Is there some logic around that to only fire a click on the
first element found? It seems to be doing just that, but this certainly
doesn't seem to be the case with assertions: if (instead of the ugly elementIdAttribute stuff above) I then do something like:
browser.expect.element(selector).to.have.attribute('class').which.contains('checked');
... that'll pass if ANY element matching the selector has a "checked" class. Which is wrong. I want to check that the element I clicked has the "checked" class.
Surely... there's a better way than this? Even the way I'm doing it above is assuming that the element found by click() is the same one found by this.api.element('css selector', selector)
I guess ideally I want something to return me a reference to an element - which is what does - but I can't pass that ID into click() or element()... can I?
As you can see.... I'm somewhat new to this, and struggling with some basic concepts. Any pointing in the right direction would be appreciated.