Reputation: 7181
I'm trying to write an evaluate function in CasperJS, but I'm running into an issue when I call a click event. Here's a quick code block to illustrate the problem:
returnVal = casper.evaluate(() ->
document.querySelector('.class').click()
return true
returnVal
is always null in the above, even when the class exists.
In my actual code I have a good deal of code to run, and I want to do multiple click events throughout.
Is it the design of CasperJS to immediately return when a click()
is called? Or am I missing something really simple?
Upvotes: 1
Views: 361
Reputation: 61892
When you register to some error event like "page.error":
casper.on("page.error", function(msg, trace) {
this.echo("Error: " + msg);
});
then you will see that click()
is not a function that can be called. PhantomJS 1.x only supports click()
on <input>
and <button>
elements and even that is not consistent. Use CasperJS' own click function if you want consistent behavior:
casper.then(function(){
this.click(".class");
});
The result of the evaluate()
call is always null (undefined
), because the return
statement is never executed. An uncaught error is thrown in the line before that.
This is written in JavaScript, but applies in exactly the same way to CoffeeScript.
Upvotes: 1