Expected behaviour of region after its visual content has been changed

Asked by Matt DeLuco

Suppose I assign the results of Region.find(<img>) to variable x, then click() that region (in this case it's a text box), and then type() text into the box.

Since the region x no longer matches <img> (as a result of typing text in the box), is the region no longer "valid"?

I would expect to be able to call "x.below(45).find(<img2>)" to search for an image below the originally returned region, but it doesn't seem to work.

Perhaps I misunderstand Region - once "found" I expect it's just a geometric representation. Is "x.below(45).find(<img2>)" again trying to find <img> from the original call to find()?

Question information

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

absolutely right:
A Region object (however it is created) is a geometric thing, that does not change its position and dimension by itself and does not repeat any find operations, that might have created the region.

So as long, as you do not change your variable x, it will always reference the same area on the screen, no matter which content it might have later on.

So the problem might be the dimension of the region x.below(45), that might not contain your image completely, so it fails.
So check your captured <img2> and either make it smaller or extend the below() value.

as a check, you might highlight the area:
x.below(45).highlight(3)
This might help, to see the position/dimension of x.below(45), which is:
Region(x.x, x.y+x.h, x.w, 45)

Revision history for this message
Matt DeLuco (hkyg) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Matt DeLuco (hkyg) said :
#3

Turns out the issue related to my misunderstanding of the Sikuli lib. But the highlight() function was a big help, thanks!