using find() with a subsequent paste() does not select the entry field

Asked by Shawn Robertson

I have been reading the region section in the sikuli guide as well as some stackoverflow articles and maybe i have the idea all wrong...

I want sikuli to find an area of the screen (this area contains a text field) and once it finds this area i want to paste some text.)

example i'm opening the firefox web browser and when it opens, the default field that has focus is the google search box in the middle of the page, i want sikuli to find the URL ADDRESS bar at the top and paste in a URL.

I know i could use a CLICK method or also hit SHIFT + TAB times but I would like to be simple.

I thought i could do this:

find(image.png, paste('www.example.com'))

but that doesn't work, sikuli just pastes teh text into the field that has focus

i also tried:

ClickMeRegion = find('image.png')
ClickMeRegion.paste('www.example.com')

again that just pasted the URL into the field that has focus.

Any help is much appreciated or a nudge in the right direction.

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

A GUI element (like you do it manually) needs to get the focus, before entering anything, if it does not have the focus yet (as in your case).

So you need a click action before pasting.

So you could either do:
find(<image>)
paste(getLastMatch(), "some text") # paste does a click before pasting

or
find(<image>)
click(getLastMatch()) # explicit click
paste("some text")

or (most compact ;-)
paste(<image>, "some text") # paste does find, click and paste

In all cases, the <image> must define a target offset, so the field is activated.

BTW:
With Sikuli it always is a temptation, to first think about the visual approach.
But in some cases using the keyboard instead might be more robust, especially if some shortcut is available.

In this case using ctrl+l (lowercase L, cmd+l on Mac)) works for all browsers to select the address bar.

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#2

Thanks Raiman!

I agree, the temptation is there and I have been slowly weening myself off of relying purely on the visual approach. I have several old scripts that i went back and redid because i was not satisfied with the amount of time and work it took to click through GUI elements and revamped the script to use keyboard shortcuts.

I was not aware of the CTRL+L and thats perfect. I should have googled "shortcut to bring focus to address bar.

I understand the concept now behind what to do and how to handle the image from the find() and using the getlastmatch() with it. find() just finds something and then you have to run another method to handle what you found

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#3

Thanks RaiMan, that solved my question.