title: How to force Firefox to be the foreground application when testing with Selenium on Mac OS X
body: <p>We recently started testing our Django-based application using Selenium. Tests run fine on Linux, but some fail on Mac OS X. We're using Firefox as the browser in both cases, and it took us a while (and some luck) to figure out that the important difference between the two cases is whether FF is running as the foreground application or as a background window.  Here's what happens on Linux:</p>
  
  <ol>
  <li>Selenium tells Firefox to go to a user registration page.</li>
  <li>Selenium fills in the user name and an <em>invalid</em> email address.</li>
  <li>Selenium changes focus from the email address field to another field on the same page (it happens to be the search box, but that's not important---all that matters is the change-of-focus event).</li>
  <li>The Javascript validation code in the web page notices that the email address is invalid and inserts an error message in the page.</li>
  <li>Selenium detects that error message and marks the test as passed.</li>
  </ol>
  
  <p>When we run on Mac OS X, however, step #4 doesn't happen <em>unless</em> we manually foreground the Firefox window while the test is running---if we leave it in the background (which is where it comes up by default), the Javascript in the browser doesn't get the change-of-focus event, so the error message is never inserted in the page's DOM, so Selenium times out waiting for it, and the test fails.</p>
  
  <p>Can we force Selenium to foreground the browser when tests run, so that our Javascript will get events as we want it to?  If so, how?</p>