title: How to execute javascript from casperjs?
body: <p>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).</p>
  
  <pre><code>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();
  });
  </code></pre>
  
  <p>When I run this script, I do visit <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> (as evidence from the screenshot) but no alert box shows up.  </p>
  
  <p>Does anyone know how to run javascript from CasperJS?</p>
  
  <p>Thanks!</p>