Windows: App.open: switch instance after creating multiple

Asked by larryli on 2020-02-19

Now, I use 2.0.2 version.
I want to create some instance for notpad and switch active between these instance.

myApp = App("C:\\Windows\\system32\\Notepad.exe")
myApp.open()
type("1111")
myApp.open()
type("2222")
sleep(5)
print myApp.hasWindow() -> always false

temp = App("Notepad")
print temp .hasWindow() -> always false

as the plan, I want to refer the following code to switch each installed. but hasWindow() is false.
for n in range(100):
        w = myApp.window(n)
        if not w: break # no more windows
        w.highlight(2) # window highlighted for 2 second

so it can not work, I change another way, App.focus("Notepad.exe",0), but there is the following error.
it seems not work, it does not change front

how to use it?
thanks

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2020-02-19
Last reply:
2020-02-26
RaiMan (raimund-hocke) said : #1

I am sorry. I have tested on Windows 10 and have to admit, that it has bugs.

Will come back later.

larryli (larryli2020) said : #2

thanks for your answer.
I will also study it.

larryli (larryli2020) said : #3

maybe the following part has problem.

this.appPID = Integer.parseInt(appPID);

so reset(); is called, the PID is -1

RaiMan (raimund-hocke) said : #4

the solution is lowercase/uppercase in app name.

This works:
myApp = App("C:\\Windows\\system32\\notepad.exe")
myApp.open()
if (not myApp.isRunning()):
  exit(1)
type("n", Key.SHIFT+Key.CTRL) # see comment
wait(3)
myApps = App.getApps("notepad.exe")
print myApps
app1 = myApps[0]
app2 = myApps[1]
app1.focus()
app1.window().highlight(2)
app2.focus()
app2.window().highlight(2)

comment: currently it is not possible to open a second instance with the same application name (notepad.exe in this case), but with the type-hack you can create a new instance, which is then recognized.

I will add a fix to 2.0.4, that app name comparisons are always don in lowercase on Windows.

Can you help with this problem?

Provide an answer of your own, or ask larryli for more information if necessary.

To post a message you must log in.