title: CasperJS can't open link.href
body: <p>I have a link button on the page:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;a id="quote" href="quote.html" target="_blank"&gt;Quote&lt;/a&gt;
  </code></pre>
  
  <p>At first I click the link:</p>
  
  <pre class="lang-js prettyprint-override"><code>casper.thenClick('#quote');
  </code></pre>
  
  <p>But I can't capture the pop-up window. So I get the url of the link and open it in current window:</p>
  
  <pre class="lang-js prettyprint-override"><code>var url = '';
  
  function getQuoteStartUrl() {
      var link = document.querySelector('a#quote');
      return link.getAttribute('href');
  }
  
  casper.thenOpen(url, function() {
      this.echo(url);
      this.echo(this.getTitle());
  });
  </code></pre>
  
  <p>The url is correct but the page is empty. Then I try this:</p>
  
  <pre class="lang-js prettyprint-override"><code>var url = 'http://quote.html';
  
  casper.thenOpen(url, function() {
      this.echo(url);
      this.echo(this.getTitle());
  });
  </code></pre>
  
  <p>It works.
  Finally I know why it doesn't work: It bind steps before the function call. So I try this:</p>
  
  <pre class="lang-js prettyprint-override"><code>casper.then(function() {
      this.echo(url);
      this.thenOpen(url);
      this.echo(this.getTitle());
  });
  </code></pre>
  
  <p>It works too.</p>