← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #266528]: app.focus() not working after window title change (Windows 8.1)?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
might have been misunderstandable:
- only in version 2015-05-08+ I think the problems are fixed.

The most reliable way, to get an APPLICATION back to front, now is, to
create an App object in the beginning using

myApp = App("someText")

where someText can be either
1. the absolute path to an .exe
2. the name of an app, that can be found on the system path as someText.exe
3. part of the window title of an ALREADY RUNNING app

The version 3 only leads to a reliable app object in the case, that the
application owning the given window can be started by only giving it's
name (currently it is not yet evaluated, from where in the file system
the app can be (re)started)

and then later only use myApp.open() or myApp.focus(), which should
either focus the app with it's frontmost window or open it, if it is not
already running (myApp must have been defined then with 1. or 2. of
course).

... and a myApp setup() this way can be reliably closed using myApp.close(), which in the myApp object resets the pid to -1.
A later use of myApp.open() will reopen the app, since it still knows what .exe should be started.

With such an reliable app object you can check the running state using
myApp.getPID(): if it is not -1, then it should be still running.

... and with such an reliable app object, with each myApp.focus() it is
checked, wether the app is still running (checking the PID). If it is no
longer running it will be reopened using the initially given information
about the exe.

But of course there might still be quirks, since this App stuff is
historically very inconsistent especially across the supported system
versions. I am still on the way to make it more consistent, but the
above mentioned things work.

BTW: in the 0507 version in fact App.focus("part of window title") did
not work anymore.

One more thing:
If you use this way, after an myApp.open() or myApp.focus(), myApp.getWindow() returns the window title of the currently frontmost window of this app.

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