lib/actions.js
function changeDropdownIndex(page, ph, selectorAndIndex, callback) {
    page.evaluate(function (selectorAndIndex) {
        try {
            var selector = selectorAndIndex[0];
            var index = selectorAndIndex[1];

            var element = document.querySelector(selector);
            element.selectedIndex = index;

            // 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);
    }, selectorAndIndex);
}
function changeDropdownIndex(page, ph, selectorAndIndex, callback) {
    page.evaluate(function (selectorAndIndex) {
        try {
            var selector = selectorAndIndex[0];
            var index = selectorAndIndex[1];

            var element = document.querySelector(selector);
            element.selectedIndex = index;

            // 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);
    }, selectorAndIndex);
}
function changeDropdownIndex ( page , ph , selectorAndIndex , callback ) { page . evaluate ( function ( selectorAndIndex ) { try { var selector = selectorAndIndex [ 0 ] ; var index = selectorAndIndex [ 1 ] ; var element = document . querySelector ( selector ) ; element . selectedIndex = index ; // 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 ) ; } , selectorAndIndex ) ; }
Change the dropdown index of a dropdown box
@param page
@param ph
@param {array} selectorAndIndex index 0 - selector
index 1 - value
@param {pageCallback} callback
Change the dropdown index of a dropdown box