title: Casperjs click method
body: <p>I'm pretty new to casperjs and javascript in general, but I have pretty extensive coding experience in other realms. Currently the code I'm trying to get running is just going to a website and clicking on a link, which should be straightforward, but I'm having trouble.</p>
  
  <pre><code>var casper = require('casper').create();
  var x = require('casper').selectXPath;
  
  casper.start('http://www.guru.com/emp/search.aspx?keyword=#&amp;&amp;page=1&amp;sort=Earnings');
  
  casper.then(function() {
      this.test.assertExists({
          type: 'xpath',
          path: '//*[@class="paddingLeft5 txt11px txt666"]/a[text()="Next"]'
      }, "Got Here");
  });
  
  casper.then(function() {
      var firstUrl = this.getCurrentUrl()
  });
  
  casper.thenClick(x('//*[@class="paddingLeft5 txt11px txt666"]/a[text()="Next"]'), function() {
      console.log("Woop!");
  });
  
  casper.waitFor(function check() {
      return this.evaluate(function() {
          return this.getCurrentUrl() != firstUrl;
      });
  }, function then() {
      console.log(this.getCurrentUrl());
  });
  
  
  casper.run();
  </code></pre>
  
  <p>currently this times out after 5000ms without wrapping in the waitFor it simply prints the same url twice.</p>