lib/actions.js
function clickElement(page, ph, selectorAndOptions, callback) {

    var selector = selectorAndOptions[0];
    var options = selectorAndOptions[1];

    function clickSelector(selector) {
        try {
            var button = document.querySelector(selector);
            var ev = document.createEvent("MouseEvent");
            ev.initMouseEvent(
                "click",
                true /* bubble */, true /* cancelable */,
                window, null,
                0, 0, 0, 0, /* coordinates */
                false, false, false, false, /* modifier keys */
                0 /*left*/, null
            );
            button.dispatchEvent(ev);
        } catch (error) {
            return error
        }
    }

    var oldUrl;

    async.waterfall([
        function (callback) {
            page.get('url', function (url) {
                oldUrl = url;
                callback();
            });
        },
        function (callback) {
            page.evaluate(clickSelector, 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;
                }
                checks.ajaxCallback(page, ph, oldUrl, options, callback);
            }, selector);
        }
    ], function (error, page, ph) {
        callback(error, page, ph);
    });
}
function clickElement(page, ph, selectorAndOptions, callback) {

    var selector = selectorAndOptions[0];
    var options = selectorAndOptions[1];

    function clickSelector(selector) {
        try {
            var button = document.querySelector(selector);
            var ev = document.createEvent("MouseEvent");
            ev.initMouseEvent(
                "click",
                true /* bubble */, true /* cancelable */,
                window, null,
                0, 0, 0, 0, /* coordinates */
                false, false, false, false, /* modifier keys */
                0 /*left*/, null
            );
            button.dispatchEvent(ev);
        } catch (error) {
            return error
        }
    }

    var oldUrl;

    async.waterfall([
        function (callback) {
            page.get('url', function (url) {
                oldUrl = url;
                callback();
            });
        },
        function (callback) {
            page.evaluate(clickSelector, 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;
                }
                checks.ajaxCallback(page, ph, oldUrl, options, callback);
            }, selector);
        }
    ], function (error, page, ph) {
        callback(error, page, ph);
    });
}
function clickElement ( page , ph , selectorAndOptions , callback ) { var selector = selectorAndOptions [ 0 ] ; var options = selectorAndOptions [ 1 ] ; function clickSelector ( selector ) { try { var button = document . querySelector ( selector ) ; var ev = document . createEvent ( "MouseEvent" ) ; ev . initMouseEvent ( "click" , true /* bubble */ , true /* cancelable */ , window , null , 0 , 0 , 0 , 0 , /* coordinates */ false , false , false , false , /* modifier keys */ 0 /*left*/ , null ) ; button . dispatchEvent ( ev ) ; } catch ( error ) { return error } } var oldUrl ; async . waterfall ( [ function ( callback ) { page . get ( 'url' , function ( url ) { oldUrl = url ; callback ( ) ; } ) ; } , function ( callback ) { page . evaluate ( clickSelector , 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 ; } checks . ajaxCallback ( page , ph , oldUrl , options , callback ) ; } , selector ) ; } ] , function ( error , page , ph ) { callback ( error , page , ph ) ; } ) ; }
Clicks a css selector on the page
@param page
@param ph
@param {array} selectorAndOptions Index 0 - {string} selector CSS Selector
Index 1 - {int} options
0 – callback immediately
1 – expect ajax, callback when the dom changes
2 – expect page navigation, callback when the url changes and document is ready
@param {pageCallback} callback
Clicks a css selector on the page