I've seen several mentions of an issue when running tests in Firefox: the Flash player doesn't load the SWF if the browser window doesn't have focus. This causes sporadic test failures if the system used for running tests is doing anything else. I've verified that if the Firefox browser is behind IE the test will hang until it times out or else I bring Firefox to the foreground manually.

A workaround that allows the Selenium2/WebDriver test to bring the browser to the front or to override this behavior of the player would be much appreciated.

  • Apropos of bringing browser to front, is not it possible for you to not execute any other application during test execution.
    – Tarun
    May 13, 2011 at 6:25
  • @Tarun The reason for the question is that there are some other processes that need to run in the same windowing session as the browser. With some care, we can get the browser to run in front 90% of the time. Of course, this means that every 10th (or so) test will report failure whether or not there is a problem with the application under test. I hope there is (or will be) a WebDriver function analogous to the Selenium windowFocus function that allows the test to assure the browser window has focus.
    – John
    May 14, 2011 at 3:26

1 Answer 1


I've copy/pasted this answer from the webdriver groups.

Hi, The focus thing is a real problem for Firefox (in particular) and becomes even harder when tests are run in parallel for obvious reasons.

We have avoided stealing focus for a window because people tend to run a suite of webdriver tests and then get on with something else whilst they're running. The best bet would be to call "window.focus" using the JavascriptExecutor service immediately before calling the flex app. If this doesn't work, you might consider using a tool to handle the window focusing in addition to webdriver: Windows exposes a few methods that might be useful and which could be accessed by JNA[1] for example.

Is this something that other people have been struggling with too?

Regards, Simon

Another thing you could do is to use a tool like desktops to make sure your browsers are opened on their own desktop. If you use selenium RC just start RC from the desktop you want your browser to open on.

  • This question was posted after looking to that webdriver and selenium forums. After this answer, we decided to try using javascript to bring Firefox to the front, our attempts using Firefox 3.6 and WebDriver 2.0b3 aren't successful. We tried profile.setPreference("dom.disable_window_flip", false) which seemed to take effect, though driver.executeScript("window.focus()") still didn't produce the desired result. Perhaps the script's window wasn't the right one to invoke focus() on. Certainly JNA would present problems trying to run the test on a remote machine.
    – John
    May 25, 2011 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.