need help on region.text() based on the position click

Asked by Ninja Mustang

How can I add the x y coordinate based on where the button.png is located on the screen?

I have the following:

x = 100
y = 50
click("button.png")
r = Region(x,y,400,200)
test1 = r.text()

I saw in log, the click button is [500,300]. I would like to them to x and y so the new region would be
Region(600,350,400,200)

or please suggest me alternative method.

Thanks!

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

the click location ([500,300] in your case) is the center of the match of the used image (button in your case)

click("button.png")
button = getLastMatch() # the area of the button image match

so depending how the new region should be positioned relative to the button match:

-- with ref to the top left corner of the match:
r = Region(button.getTopLeft().x+100, button.getTopLeft().y+50, 400 200)

-- with ref to the click point:
r = Region(button.getCenter().x+100, button.getCenter().y+50, 400 200)

the Region spatial methods (right(), above(), ...) might as well be used to create suitable regions relative to other regions.

version 1.0.1 has some convenience functions for these cases.

Revision history for this message
Ninja Mustang (ninjamustang) said :
#2

Thanks RaiMan, that solved my question.