I can not get "this.mouse.click ()" to work with casperjs

I am trying to understand casperjs but struggling with this. Can someone please explain to me why this works (he goes to http://www.w3schools.com/html/default.asp ):

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

casper.start('http://www.w3schools.com/');

casper.then(function(){

  this.click('a.btn'); 
});

casper.then(function(){

   console.log('Location is now: ' + this.getCurrentUrl());
});

casper.run();

But if I replaced

this.click('a.btn'); 

with

this.mouse.click('a.btn');

Then it remains on one page. I thought where the same thing.

+4
source share
1 answer

According to Instant Testing with CasperJS:

casper.click()creates an event and sends it to the target event, but casper.mouse.click()has no relation to any element, but simply produces a mouse action at a given position.

, (HTML- w3schools.com , , JavaScript ).

. : , ! script, :

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

casper.options.viewportSize = {width: 1024,height: 768};

casper.start('http://www.w3schools.com/');

casper.then(function(){
  this.mouse.click('a.btn'); 
});

casper.then(function(){
   console.log('Location is now: ' + this.getCurrentUrl());
});

casper.run();

PhantomJS, SlimerJS. SlimerJS HTML-, . this.capture("aboutToClick.png"); , this.mouse.click('a.btn'); .

ASIDE: var mouse, , : casper .

+4
source

All Articles