Focus on webdriver window

590 views
Skip to first unread message

vin

unread,
Nov 12, 2008, 7:42:07 AM11/12/08
to webdriver
I am using webdriver and run tests in parallel. I have some flex code
as part of my application. Flex(Flash) does not load if focus is not
on the window. Because the focus can only be one of the window, I
would like to know how to focus on window programmatically using
webdriver. I can use this in places where it calls flex application.
I tried switchTo() but it did not work. Also tried window.focus() in
JSP which also did not work.
Please reply

Simon Stewart

unread,
Nov 12, 2008, 9:29:40 AM11/12/08
to webd...@googlegroups.com
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

[1] https://jna.dev.java.net/

John

unread,
May 24, 2011, 11:23:50 PM5/24/11
to webd...@googlegroups.com
The message from Simon suggesting that tests invoke javascript window.focus() was cited in a SQA stackoverflow answer. I didn't bother to reply to this when I first saw it because it was so old. Over the past couple of months, I've come to the conclusion that tests must be able to bring their browser to the front (at least in the case of Firefox) because not only is Flash media disabled if the window is occluded, but the javascript onchange events don't fire if sendkeys is working on a window that is on in focus.  We've tried a few things to get the javascript window.focus() call to do what we want, to no avail. There are a number of threads referring to this problem that make it look like Selenium 1 handles the situation fairly directly. It does seem as if Selenium 2.x will gain the capability someday. Life on this end would be easier if the capability were added in 2.0.

Eran M.

unread,
May 27, 2011, 6:35:39 AM5/27/11
to webd...@googlegroups.com
Hi,

A part of the support for native events for Firefox on Linux includes taking care of the focus - an additional component will prevent the window from getting notification of lost focus.
Try turning on native events via the FirefoxProfile - notice it only works for Selenium 2.

Eran

On Wed, May 25, 2011 at 4:23 AM, John <jwb...@gmail.com> wrote:
The message from Simon suggesting that tests invoke javascript window.focus() was cited in a SQA stackoverflow answer. I didn't bother to reply to this when I first saw it because it was so old. Over the past couple of months, I've come to the conclusion that tests must be able to bring their browser to the front (at least in the case of Firefox) because not only is Flash media disabled if the window is occluded, but the javascript onchange events don't fire if sendkeys is working on a window that is on in focus.  We've tried a few things to get the javascript window.focus() call to do what we want, to no avail. There are a number of threads referring to this problem that make it look like Selenium 1 handles the situation fairly directly. It does seem as if Selenium 2.x will gain the capability someday. Life on this end would be easier if the capability were added in 2.0.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Reply all
Reply to author
Forward
0 new messages