Selenium InternetExplorerDriver doesn’t get focus on the window

Seems you have opted to add all the InternetExplorerDriver related capabilities.

Browser Focus

The challenge is that IE itself appears to not fully respect the Windows messages we send to the IE browser window (WM_MOUSEDOWN and WM_MOUSEUP) if the window doesn’t have the focus. Specifically, the element being clicked on will receive a focus window around it, but the click will not be processed by the element. Arguably, we shouldn’t be sending messages at all; rather, we should be using the SendInput() API, but that API explicitly requires the window to have the focus. We have two conflicting goals with the WebDriver project.

So first, we strive to emulate the user as closely as possible. This means using native events rather than simulating the events using JavaScript.

Second, we want to not require focus of the browser window being automated. This means that just forcing the browser window to the foreground is sub-optimal.

An additional consideration is the possibility of multiple IE instances running under multiple WebDriver instances, which means any such bring the window to the foreground solution will have to be wrapped in some sort of synchronizing construct (probhably a mutex) within the IE driver’s C++ code. Even so, this code will still be subject to race conditions, if, for example, the user brings another window to the foreground between the driver bringing IE to the foreground and executing the native event.

The discussion around the requirements of the driver and how to prioritize these two conflicting goals is ongoing. The current prevailing wisdom is to prioritize the former over the latter, and document that your machine will be unavailable for other tasks when using the IE driver. However, that decision is far from finalized, and the code to implement it is likely to be rather complicated.

Solution

As an interim solution you can add the capability:

ieCapabilities.setCapability("requireWindowFocus", false);

Leave a Comment