title: Focus on input by using jQuery
body: <p>I'm working on a webpage where jquery is loaded and there is an input field on the webpage, which supports auto completion, so after typing several characters, a selection of suggestion box shows itself. By using dev tools' console, i can be able force that suggestion list to be generated and be appeared on demand, by executing following jquery functions (<em>in browser console</em>):</p>
  
  <pre><code>$('input#PrincipalPolicyHolder_EmploymentOccupationDescription').val("soft");
  
  setTimeout(function() { $('input#PrincipalPolicyHolder_EmploymentOccupationDescription').focus(); }, 5000);
  
  setTimeout(function() { $('input#PrincipalPolicyHolder_EmploymentOccupationDescription').keyup(); }, 6000);
  </code></pre>
  
  <p>The delay is required for me to change the focus to the window from console. These jQuery commands are enough to get <code>$('#PrincipalPolicyHolder_EmploymentOccupationDescription').is('focus')</code> true which is required to generate a list of suggestions, as long as i don't click to somewhere else.</p>
  
  <p>However, the same steps don't work in casperjs environment. This is how i execute;</p>
  
  <pre><code>casper.then(function () {
      this.evaluate(function () {
          $('input#PrincipalPolicyHolder_EmploymentOccupationDescription').val("soft");
          $('input#PrincipalPolicyHolder_EmploymentOccupationDescription').focus();
          $('input#PrincipalPolicyHolder_EmploymentOccupationDescription').keyup();
      });
  });
  </code></pre>
  
  <p>I also tried to use sendKeys with <code>keepFocus: true</code>, but never got <code>is(':focus')</code> check positive. Is there any way to accomplish this?</p>
  
  <p>Edit:
  I narrowed down the problem to work on a very simple webpage, Here is the code snippet that captures the issue:</p>
  
  <pre><code>var casper = require('casper').create({
      verbose: true,
      loglevel: "debug"
  });
  
  casper.start('http://jsfiddle.net/vhermL99/embedded/result/');
  
  casper.on('remote.message', function(msg) {
      this.echo('remote message caught: ' + msg);
  });
  
  casper.withFrame(0, function () {
      casper.thenEvaluate( function () {
      var input = $('#input1');
      input.val("value set by jquery");
      input.focus();
      console.log("is input focussed: " + input.is(':focus'));
      });
      casper.then(function () {
      this.capture('before-sendkey.png');
      });
      casper.then(function () {
      casper.sendKeys('#input1', 'value set by sendKeys', {'reset': true, 'keepFocus': true});
      });
      casper.thenEvaluate(function () {
      console.log("is input focussed: " + $('#input1').is(':focus'));
      });
      casper.then(function () {
      this.capture('before-sendkey.png');
      });
  
  });
  
  casper.run();
  </code></pre>
  
  <p>The expectation is having <code>.is(':focus')</code> true in one of two methods.</p>