Assert exists on focused window

Asked by Erisu B

After switching from Sikuli method for Unit Testing to python's unittest, I am beginning to receive this error when asserting that an image exists within a focusedWindow.

Example Code:
window = App.focusedWindow()
assert window.exists("image.png", 30)

Error Message:
AttributeError: 'NoneType' object has no attribute 'exists'

Any ideas why I am now getting this error but not previously?
What would be the best method for checking if an image exists within a focusedWindow?

Note: I am looking on the focusedWindow because that window could load at any location of screen so defining a set region x, y, etc would not always be accurate.

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
Roman Podolyan (podolyan-roman) said :
#1

> Any ideas why I am now getting this error but not previously?

I would guess that's because returned type of App.focusedWindow() is not defined, so it literally hasn't any .exist method (kudos for the tip goes to Capitan Obvious).

So, I would try to convert it to some Sikuli type, which has that method.

Why not try to get some coordinates and dimensions from what App.focusedWindow() returns and construct a Region from that manually?

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

--- So, I would try to convert it to some Sikuli type, which has that method.
App.focusedWindow() returns a Region of the window of the active app, that is the frontmost.

So if it has worked before, now in the new setup, it does not exist a frontmost window or the call comes too fast after the last action, that influenced the GUI.

So I would first try to insert a wait(2) before the App.focusedWindow() and see what happens. If it works now, the waiting time can be reduced to a suitable value.

Can you help with this problem?

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

To post a message you must log in.