title: How can I retrieve the href element from a button in a casperJS script?
body: <pre><code>casper.then(function() {
  this.test.assertExists({
      type: 'xpath',
      path: '//*[@id="wrapper"]/div[1]/a[2]'
  }, "Found Multiviewer button");
  </code></pre>
  
  <p>});</p>
  
  <p>The above button is found but I cannot access the href element by doing:</p>
  
  <pre><code>var element = x('//*[@id="wrapper"]/div[1]/a[2]');
  
  console.log('element'+this.getElementAttribute(element,'href'));
  </code></pre>
  
  <p>results in:</p>
  
  <pre><code>TypeError: 'undefined' is not a function (evaluating 'this.getElementAttribute(element,'href')')
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>this.getElementAttribute('//*[@id="wrapper"]/div[1]/a[2]','href')')
  </code></pre>
  
  <p>casperJS version is 1.1.0-beta3 (OSX 10.8.5)</p>
  
  <p>Once I've retrieved the URL I then need to open it...</p>
  
  <pre><code>var baseTargetUrl;
  casper.then(function() {
      var element = x('//*[@id="wrapper"]/div[1]/a[2]');
      console.log('url is: '+this.getElementAttribute(element,'href'));
      baseTargetUrl = this.getElementAttribute(element,'href');
  });
  
  casper.thenOpen(baseTargetUrl, function() {
      this.echo(this.getTitle());
  });
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>FAIL TypeError: 'undefined' is not an object (evaluating 'url.toLowerCase')
  #    type: uncaughtError
  #    error: 'undefined' is not an object (evaluating 'url.toLowerCase')
  #           TypeError: 'undefined' is not an object (evaluating 'url.toLowerCase')
  #               at cleanUrl (/usr/local/lib/node_modules/casperjs/modules/utils.js:112)
  #               at open (/usr/local/lib/node_modules/casperjs/modules/casper.js:1405)
  #               at _step (/usr/local/lib/node_modules/casperjs/modules/casper.js:1832)
  #               at runStep (/usr/local/lib/node_modules/casperjs/modules/casper.js:1553)
  #               at checkStep (/usr/local/lib/node_modules/casperjs/modules/casper.js:399)
  #    stack: not provided
  TypeError: 'undefined' is not an object (evaluating 'url.toLowerCase')          
    /usr/local/lib/node_modules/casperjs/modules/utils.js:112 in cleanUrl
    /usr/local/lib/node_modules/casperjs/modules/casper.js:1405 in open
    /usr/local/lib/node_modules/casperjs/modules/casper.js:1832 in _step
    /usr/local/lib/node_modules/casperjs/modules/casper.js:1553 in runStep
    /usr/local/lib/node_modules/casperjs/modules/casper.js:399 in checkStep
  FAIL TypeError: 'undefined' is not an object (evaluating 'url.toLowerCase')
  #    type: error
  #    subject: false
  #    error: "TypeError: 'undefined' is not an object (evaluating 'url.toLowerCase')"
  #    stack: in cleanUrl() in /usr/local/lib/node_modules/casperjs/modules/utils.js:112
  in open() in /usr/local/lib/node_modules/casperjs/modules/casper.js:1405
  in _step() in /usr/local/lib/node_modules/casperjs/modules/casper.js:1832
  in runStep() in /usr/local/lib/node_modules/casperjs/modules/casper.js:1553
  in checkStep() in /usr/local/lib/node_modules/casperjs/modules/casper.js:399
  </code></pre>
  
  <p>How should I pass the URL to the next function?</p>