← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #186581]: Filling the text in different text box while running the script next time

 

Question #186581 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/186581

    Status: Open => Answered

RaiMan proposed the following answer:
-- 1. restrict region
You generally should restrict the region to the emulator window, so searches are more reliable and faster.
Have a look at the class App for the respective features.

-- 2. Do not search unnecessary
Most people when beginning use codings like
find("some-image.png")
click("some-image.png")

or 
if exists("some-image.png"): click("some-image.png")

in both cases you can use getLastMatch(), to use the already known match:
if exists("some-image.png"): click(getLastMatch())

-- 3. tell Sikuli where to search
Especially in emulator windows, it is a good practice, that sikuli should search for the next visual left/right/above/below the last match. 

find("some-image.png")
m = getLastmatch().below().find("other image.png")
m.right().click("button.png")

-- 4. use offsets to click if possible
especially, when wanting to type into text entry fields, it is a good practice, to screenshot the description/label part of the field and use IDE's Preview to set the target offset into the field.

-- 5. using type() for text entry
With typing it is a good practice, to insert wait()'s to compensate reaction times of the GUI.

click(point_that_activates_field)
wait(0.5) # give time to GUI to switch to input mode
type("some text")
wait(0.5) # give time to GUI to be ready to accept next click action

your timing might need higher values or reduced ones might be
sufficient.

--- taking all things together for your request

emu = App("the emulator").window()
setROI(emu) # restricts all searches to the emu window

top = find("image of some fixed top part")

top.below().type(Pattern("JobCurdNumbe.png").targetOffset(150, 0),
"12399")

comment on the Pattern stuff:
when using IDE's Preview to set a higher similarity or a target offset (click point other the the image center), the image file name is turned into a Pattern object like above. You can see that in the respective .py code file or when hovering with the mouse over the thumbnail.

comment on the above usage of type():
giving a Pattern/Image/Text/Match/location as first parameter in a type() is internally turned into a click()+type() combination.
If this does not work, because of the above mentioned timing problems (-- 5.), then you have to split it into a click(); wait(); type(); wait() sequence yourself.

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.