Not working methods of the class App - close(), focus(),

Asked by Alexandr

I have the following code taken from the documentation.

firefox = App.open(r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
wait(2)
#firefox.focus()
wait(1)
firefox.close()

When I call the method of focus() or wait(). I get an error

[error] script [ HappyDev ] stopped with error in line 5
[error] AttributeError ( 'NoneType' object has no attribute 'close' )
In the previous version SikuliX these methods worked fine. Could you tell me how to solve this problem

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#2

I can't run previous version of SikuliX now, but the following code works correctly on SikuliX1.1.0 .
[Environment:]Windows7, SikuliX1.1.0
[code:]
myApp = App("firefox")
App.open(r"C:\Program Files\Mozilla Firefox\firefox.exe")
while not myApp.isRunning():
        wait(1)
myApp.focus()
myApp.close()

Revision history for this message
Eugene S (shragovich) said :
#3

You are having this problem because of how you define your firefox variable.

When you write:
firefox = App.open(r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe")

you assign the output of whatever value that is created as a result of EXECUTING the FireFox browser

The error:
[error] AttributeError ( 'NoneType' object has no attribute 'close' )

says exactly that.

To make it work properly, you must do it like was offered by @masuo and first create an instance of the type App. The you will be able to use the App methods on it.

Can you help with this problem?

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

To post a message you must log in.