Javascript phantomjs发送点击事件

Javascript phantomjs发送点击事件,javascript,phantomjs,Javascript,Phantomjs,我有以下脚本: var page = require('webpage').create(); var fs=require('fs'); console.log('The default user agent is ' + page.settings.userAgent); page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34

我有以下脚本:

var page = require('webpage').create();
var fs=require('fs');
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';
page.open('http://www.google.com/ncr', function() {
    page.viewportSize = { width: 1920, height: 1080 };
    page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
        var text = page.evaluate(function() {
            return document.getElementById('gb_70').href;
        });
        console.log(text);
        var point = page.evaluate(function() {
            var element = document.getElementById('gb_70');
            var rect = element.getBoundingClientRect();
                return {
                x:rect.left + Math.floor(rect.width / 2), y:rect.top + Math.floor(rect.height / 2)
                };
        });
        page.sendEvent('click', point.x, point.y);
        console.log(point);
        console.log(point.x);
        console.log(point.y);
        page.clipRect = {top:point.x, left:point.y, height:15, width:15};
        page.render('captureelement.png');

        page.clipRect = {top:33, left:1854, height:15, width:15};
        page.render('captureaiureadetest.png');

        page.clipRect = {top:0, left:0, height: 0, width: 0};


    console.log("Trecut");  
    fs.write('Log.html', page.content , 'w');
    fs.write('Log.txt', text , 'w');
    page.render('capturefinal.png');
    phantom.exit()
    });
});
它不会捕获元素,也不会单击它,但会获取坐标,并且不会向我发送任何错误

我是新来的幻影,请有人告诉我是怎么回事

节日快乐。

我在:''找到了这个例子,并为我工作。请参见下面的示例:

var element = document.getElementById('gb_70');
var e = document.createEvent("MouseEvents");

// If you need pass the clientX, clientY, etc., you can call
// initMouseEvent instead of initEvent
e.initEvent.apply(e, ['mouseover', true, true]);

element.dispatchEvent(e);

希望下面的方法会有用。它在1.9版中对我有效

page.evaluate(function(){
    var a = document.getElementById("ELEMENT_ON_WHICH_CLICK_TO_BE_DONE");
    var e = document.createEvent('MouseEvents');
    e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(e);
    waitforload = true;
});

这对我有用。希望这将有助于你应对这种情况

没有人?至少一个例子,一个教程,任何东西。