1

Hello guys I loved this sikuli but I found one issue related to app.open as well as app.focus

Here is my code my code has single line to test wheater app.open or focus open single instance

  App.open("C:\\program file\internet explorer\\iexplore.exe")
  Or 
  App.focus("C:\\program file\internet explorer\\iexplore.exe")

Both app.open and app.focus open explorer multiple time for eg:- suppose not any explorer open on first app.open or focus it open explorer now re run code the it again open explorer i.e now I have explorer instance

Expected to check if multiple explorer instance is open then close all and open single instance and if single open then just focus it is there any other alternative

bipin
  • 421
  • 8
  • 21

1 Answers1

2

Try this code below. I got this to work. So, basically, we are checking if the app window exists and if it does, close it. Else, it will ofcourse break from the loop.

Check the below link for the exact explanation on how window command works:

https://sikulix-2014.readthedocs.io/en/latest/appclass.html#window

myApp = App("Notepad.exe")
while(myApp.window() is not None):
    myApp.close()
    myApp = App("Notepad.exe")
Aji
  • 121
  • 8
  • Welcome to SO, this answer is low quality, you have to provide explanation with your code, how you managed to solve this problem? – Basel Issmail Mar 06 '19 at 17:51
  • 1
    Hi Basel, Thank you for the welcome. But, the answer is pretty straight forward i thought for more explanation. If the app window returns not none, i.e. it exists then, close the instance. Sorry if it wasn't more explanatory. I will edit the answer. – Aji Mar 06 '19 at 18:21