App.focus() fails to focus

Asked by akshata

Hi,

I am trying to use App.focus() to focus window1 which is hidden behind window2. I used below line in my code:

             App.focus(Window1)

It fails to focus window1 all the time. I was looking for a solution to it.

Thanks.

Question information

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

as mentioned in the docs
http://sikulix-2014.readthedocs.org/en/latest/appclass.html#the-application-class-app

Window1 must be some text, that appears in this window's title only.

If the given text appears in more than one window title, the result is not predictable.

Revision history for this message
akshata (akshata-hosmath) said :
#2

Here is my scenario:

I have Visual Studio application (window1) open on the screen and I open other window (window2) which opens and hides behind (it doesn't pop up) the window1. So, I want to get window2 up by using App.focus(window2) and this doesn't work for me. I have used appropriate window names and given window names do not appear in more than one window title. I have made sure that I have used the window title correctly.

I am looking for a solution to this scenario.

Thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

is the visual studio window at full screen?

Have you tried with other windows, than the one that does not work?

Have you tried to get a window to front that is (partly) hidden by a non-VisualStudio window?

Revision history for this message
akshata (akshata-hosmath) said :
#4

Yes the Visual Studio window is as full screen. I have tried to use App.focus() in many places to switch between windows and they seem to work most of the times.

But, in the scenario mentioned the window2 opens and hides behind and does not pop up. I wanted to focus that screen which did not pop up. And in this case App.focus() fails all the time.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

is window2 a sub window of VisualStudio?

Ok, I guess, to solve the case, you have to get the VS window out of the way for the moment and bring it back afterwards.

Revision history for this message
akshata (akshata-hosmath) said :
#6

Thanks for the solution. I tried to get the VS window out of the way for the moment and bring it back afterwards.

But, when I minimize VS window how do I focus(or restore) VS window ?
I tried the following to that but it didn't work, please let me know if there is any other way to do it.

VS = App.focus(Visual Studio)
type(" ", KeyModifier.ALT)
wait(1)
type("n")
App.focus(window2)
-------- Some other code -------
VS = App.focus(Visual Studio)
VS.focus()
type(" ",KeyModifier.ALT) -----the restore of VS window doesn't work
wait(1)
type("w")
wait(1)
type(" ",KeyModifier.ALT)
wait(1)
type("x")

Thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

the easiest possibility is to click the VS icon in the task bar.

Revision history for this message
akshata (akshata-hosmath) said :
#8

Ok. Thanks for the solution.