I'm doing some testing for an AngularJS app, I don't think the test framework is necessarily important here, but I'm trying to pass an optional variable. This variable will specify if I'm trying to grab a child element of the ID that is passed to the function
commonFunctions.elementDoesNotHaveAttribute('register-0', 'disabled', 'children[0].children[0]');
the children[0].children[0] isn't really a string, if I remove the quotes the function call fails because it can't find a child object of .children[0]
Here is the function
function elementDoesNotHaveAttribute(id, attribute, child) {
var hasElement = false;
hasElement = casper.evaluate(function (id, attribute, child) {
var element = document.getElementById(id);
if (child) {
element = element.child;
}
return element.hasAttribute(attribute);
}, id, attribute, child);
if (hasElement) {
casper.test.fail('element has' + attribute + ' but shouldn\'t');
} else {
casper.test.pass('element didn\'t have ' + attribute + ' and shouldn\'t');
}
}
How can I change either side of these equations to end up evaluating element.children[0].children[0] within my function