As a simple way to test if javascript is executing correctly from CasperJS, I'm trying to have an alert box in javascript pop up on the page. My end goal is running more complex javascript functions, but for right now I just wanted to start with something easy (i.e. if there is a native CasperJS alert box function, I don't want to use it because I want to get javascript working).
var casper = require("casper").create();
casper.start("http://www.google.com", function() {
});
casper.thenEvaluate(function() {
alert('hi');
});
casper.then(function(){
this.wait(500, function() {
this.echo("I've waited for 500 milliseconds");
});
this.capture('google.png', {
top: 0,
left: 0,
width: 1500,
height: 1000
});
});
casper.run(function() {
this.echo(this.getTitle()); // Google
this.exit();
});
When I run this script, I do visit http://www.google.com (as evidence from the screenshot) but no alert box shows up.
Does anyone know how to run javascript from CasperJS?
Thanks!