1

I use "http://104.238.150.223:8888" in order to test it, which is a html that we can paint with mouse on it, and my code is as follow:

var casper = require('casper').create();
var mouse = require('mouse').create(casper);

casper.start('http://104.238.150.223:8888',function() {
    this.echo(this.getTitle());
});

casper.then(function() {
    this.wait(2000,function() {
        this.mouse.down(0,0);
        this.mouse.move(40,40);
        this.mouse.move(60,40);
        this.mouse.down(60,40);
    });
    this.capture('test.png');
})

But it doesn't work, there is nothing in the drawing board T_T

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Chen YuFan
  • 19
  • 5

1 Answers1

0

Native event

Native dragging is not possible with PhantomJS (CasperJS is built on top of it), because each casper.mouse.*() call actually starts a new mouse action and "resets" the previous one. The press status of any mouse button is not kept between the calls. That has something to do with how PhantomJS' page.sendEvent works, which handles all the user actions through CasperJS (emphasis mine):

The first argument is the event type. Supported types are 'mouseup', 'mousedown', 'mousemove', 'doubleclick' and 'click'. The next two arguments are optional but represent the mouse position for the event.

The button parameter (defaults to left) specifies the button to push.

For 'mousemove', however, there is no button pressed (i.e. it is not dragging).

Synthetic event

You may try to trigger synthetic events with the available DOM APIs inside of casper.evaluate. You would need to

  • find the element on the page that is actually responsible of capturing those UI events and

  • trigger the appropriate events on that element: 1 x mousedown, n x mousemove and 1 x mouseup.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Thanks for your help and I make it to use mousemove, mousedown and mouseup separately in the chrome console in the way in [trigger](http://stackoverflow.com/questions/7772222/is-there-a-way-to-trigger-mousemove-and-get-event-pagex-event-pagey/14483616#14483616) , but still fail to combine them T_T – Chen YuFan Aug 28 '16 at 14:10