lib/actions.js
function setCheckboxState(page, ph, selectorAndState, callback) {
    page.evaluate(function (selectorAndState) {
        try {
            var selector = selectorAndState[0];
            var state = selectorAndState[1];
            var element = document.querySelector(selector);
            element.checked = state;

            // event is needed because listeners to the change do not react to
            // programmatic changes
            var event = document.createEvent('Event');
            event.initEvent('change', true, false);
            element.dispatchEvent(event);
            return null;
        } catch (error) {
            return error;
        }
    }, function (error) {
        // do this because if there is no error, the error is still something so we can't simply do callback(error, page, ph);
        if (error) {
            callback(error, page, ph);
            return;
        }
        callback(null, page, ph);
    }, selectorAndState);
}
function setCheckboxState(page, ph, selectorAndState, callback) {
    page.evaluate(function (selectorAndState) {
        try {
            var selector = selectorAndState[0];
            var state = selectorAndState[1];
            var element = document.querySelector(selector);
            element.checked = state;

            // event is needed because listeners to the change do not react to
            // programmatic changes
            var event = document.createEvent('Event');
            event.initEvent('change', true, false);
            element.dispatchEvent(event);
            return null;
        } catch (error) {
            return error;
        }
    }, function (error) {
        // do this because if there is no error, the error is still something so we can't simply do callback(error, page, ph);
        if (error) {
            callback(error, page, ph);
            return;
        }
        callback(null, page, ph);
    }, selectorAndState);
}
function setCheckboxState ( page , ph , selectorAndState , callback ) { page . evaluate ( function ( selectorAndState ) { try { var selector = selectorAndState [ 0 ] ; var state = selectorAndState [ 1 ] ; var element = document . querySelector ( selector ) ; element . checked = state ; // event is needed because listeners to the change do not react to // programmatic changes var event = document . createEvent ( 'Event' ) ; event . initEvent ( 'change' , true , false ) ; element . dispatchEvent ( event ) ; return null ; } catch ( error ) { return error ; } } , function ( error ) { // do this because if there is no error, the error is still something so we can't simply do callback(error, page, ph); if ( error ) { callback ( error , page , ph ) ; return ; } callback ( null , page , ph ) ; } , selectorAndState ) ; }
Sets the state of a checkbox
@param page
@param ph
@param {Array} selectorAndState index 0 - {string} selector
index 1 - {boolean} state
@param {pageCallback} callback
Sets the state of a checkbox