0

我正在尝试使用 PhantomJS 或 SlimerJS 自动化网站上的画布元素。我很难让画布元素检测我的点击按钮。从屏幕截图中,我可以看出鼠标悬停在按钮上,但它拒绝点击它们。

var page = require('webpage').create()
page.viewportSize={width: 1280, height: 768};
var fs = require('fs');
page.open('http://www.soulofsoccer.com/app/',function(){
    setTimeout(function(){ //wait for canvas to load
        page.render('soccer/step1.png','png');
        page.sendEvent("click",50,718); //menu button

         //test to click a second time
        setTimeout(function(){
            page.sendEvent("click",50,718);
            page.render('soccer/test1.png','png');
        },1000);

        //final screenshot
        setTimeout(function(){
            page.render('soccer/test.png','png');
            //phantom.exit();
            //slimer.exit();
        },2000);

    },10000); //wait for canvas to load
});

有人可以告诉我我的错误在哪里吗?

PhantomJS 版本:
1.9.8 SlimerJS 版本:0.9.5

4

1 回答 1

1

我只设法使它在 PhantomJS 2.0 中工作。

我看过页面。您必须先移动到要单击的位置,然后才能单击。鼠标移动和点击直接设置位置是有区别的。似乎这个页面非常特别地首先注册了鼠标移动,然后才启用点击操作。

page.render('test19_step1.png');
page.sendEvent("mousemove",50,718); //menu button

setTimeout(function(){
    page.sendEvent("click",50,718);
},1000);

setTimeout(function(){
    page.render('test19_test.png');
    phantom.exit();
},2000);

我建议您为此使用抽象:

function clickInCanvas(x, y, callback, delayBetween) {
    delayBetween = delayBetween || 50;
    page.sendEvent("mousemove", x, y);

    setTimeout(function(){
        page.sendEvent("click", x, y);
    }, delayBetween);

    setTimeout(callback, delayBetween*2);
}
于 2015-04-30T07:11:54.597 回答