← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #184407]: Focus function call on Firefox app causes focus to be lost on app

 

Question #184407 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/184407

    Status: Open => Answered

RaiMan proposed the following answer:
Handling of Firefox sessions (or other modern singleProcess/multiWindow
applications) on Windows is a bit tricky.

You approach especially when rerun in the IDE does not work generally.
The current implementation of the App class in Windows is not able to handle Firefox as expected.

Try this instead, which works for me (Win 7 32Bit):

ff = r"C:\Program Files\Mozilla Firefox\firefox.exe"
ffA = App("Mozilla Firefox")
if not ffA.window():
    App.open(ff)
for i in range(10):
    if ffA.window(): break
    wait(1)
ffA.focus()
App.focusedWindow().highlight(2) # only to check

If at least one FF window is already open, the frontmost one is focused.
If not, we open FF and wait for a window (FF has many windows open for performance reasons, but most of them are invisible normally) and finally focus.

As you can see, only the approach, using the window title to identify
the "app", works. If you have more than one FF window open, you have to
use a more specific part of the window title.

Just to get an impression, run this snippet 2 or 3 times in the IDE:

ff = r"C:\Program Files\Mozilla Firefox\firefox.exe" # opens a new ff window
ffA = App.open(ff)
wait(3)
for i in range(100):
    w = ffA.window(i)
    if not w: break
    print w

and look at the list of windows ;-)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.