App focus not setting focus as expected

Asked by Beth Griffin

I do the following, and yet sometimes the application (Visual Studio) does not start with focus and other times it does:

VSApp = App(VS_exe_path)
VSApp.open()
# wait for visual studio to start. And it could take almost 90 seconds to start up on a slow machine
wait("VSStartPage.png", 90)
type("l", KEY_CTRL + KEY_ALT)
if not exists("VSexplorerWithFocus.png",5):
    # report a problem
else:
    # open a solution file

I can tell that the type() didn't go to Visual Studio because I watched the code run. If I add a VSApp.focus() in between the "wait()" and "type()", Visual Studio loses focus if it has it, takes it if it doesn't (meaning no real change in behavior).

Any tips on how to prevent this? I looked at the similar question posted about Firefox (184407), but I know there is only 1 Visual Studio application/window up and running (task manager only shows one devenv.exe process). There may be other apps running, but I thought that by doing the "VSApp = App()" I ensured the VSApp.focus would only affect the one and only Visual Studio instance running.

Thanks,
Beth

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Beth Griffin
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

I found, that on windows, the only reliable focus() variant is the one where you use a distinctive part of the window text, to get the respective window to front. I never had a look at the code, so I cannot tell you what is behind this behavior.

The other option always is (if you are sure, the app has only one window or you know the window number), to click in an area of VSApp.window(), that brings it to front, but does not do anything.

Revision history for this message
Beth Griffin (beth-griffin) said :
#2

Since I watch for an image that is contained on the VS startup, I click on that match to ensure focus.