PhantomJS; click an element

前端 未结 11 839
借酒劲吻你
借酒劲吻你 2020-11-21 23:53

How do I click an element in PhantomJS?

page.evaluate(function() {
    document.getElementById(\'idButtonSpan\').click();  
});

This gives

11条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 00:11

    Document.querySelector(element).click() works when using Phantomjs 2.0

    click: function (selector, options, callback) {
        var self = this;
        var deferred = Q.defer();
        options = options || {timeout:1000}; 
        setTimeout(function () { 
            self.page.evaluate(function(targetSelector) {
                $(document).ready(function() {
                    document.querySelector(targetSelector).click();
                }) ;
            }, function () {
                    deferred.resolve();
            }, selector);
        }, options.timeout);
        return deferred.promise.nodeify(callback);
    },
    

提交回复
热议问题