How to pass an image as argument into subroutine

Asked by Petr Fejfar

Hi all,

I'd like to fill-in a form repeatedly using a subroutine for this task, e.g.

def fill_form(code,image):
 click(xxxxx) # captured image
 type(code)
 click(yyyyy) # captured image
 click(image) # image passed as the argument
 click(zzzzz) # captured image
        ...
 click(OK) # captured image

fill_form("999",image1)
fill_form("998",image2)
etc...

image1 is the captured image having name i.png, which *exists* in the same folder where .py script resides. When I run the script, I got the error:

Traceback (most recent call last):
  File "C:\Users\PETRFE~1\AppData\Local\Temp\sikuli-tmp1397197302814887988.py", line 37, in <module>
    fill_form("999","i.png")
  File "C:\Users\PETRFE~1\AppData\Local\Temp\sikuli-tmp1397197302814887988.py", line 7, in fill_form
    click(image)
  File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\Region.py", line 119, in click
  Line 11, in file C:\Users\PETRFE~1\AppData\Local\Temp\sikuli-tmp1397197302814887988.py

 at org.sikuli.script.Region.wait(Region.java:289)
 at org.python.proxies.sikuli.Region$Region$1.super__wait(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)

org.sikuli.script.FindFailed: FindFailed: i.png can't be found.
  Line 11, in file C:\Users\PETRFE~1\AppData\Local\Temp\sikuli-tmp1397197302814887988.py

Please, could somebody point me what I'm missing?

Thx, pf

Question information

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

Working in the IDE?

The script that brings the error is run in temp folder, which means it is not saved yet.

you say: image1 is the captured image having name i.png, which *exists* in the same folder where .py script resides.
question: what .py script?

Revision history for this message
Petr Fejfar (pf1957) said :
#2

> Working in the IDE?

Yes.

> The script that brings the error is run in temp folder, which means it is not saved yet.

Strange... I've opened previously saved sikuli script from the disk i.e. I saved the script, shut down Sikuli, run it again an opened the script

> you say: image1 is the captured image having name i.png, which *exists* in the same folder where .py script resides.
> question: what .py script?

.py file the sikuli script is saved in. In this folder, I have .html and .py files and set of related .png images.

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

ok, when working in IDE, the script is always in a temp folder, sorry for rubbish ;-)

So if you are sure, the image is in the .sikuli folder of the script you are running in IDE, then the image cannot be found within 3 seconds at the time the script is run.

Revision history for this message
Petr Fejfar (pf1957) said :
#4

> So if you are sure, the image is in the .sikuli folder of the script you are running in IDE,

Yes, I am.

> then the image cannot be found within 3 seconds at the time the script is run.

But I do not understand why:
1. If I execute click("i.png") in the main script body, it works i.e. "i.png" is found (In the IDE the image is shown)
2. If I pass it to subroutine fill_form("999","i.png") it cannot be found (in the IDE the image is shown as well)
3. If I tried prepend getImagePath() ind the soubroutine, it still fails complaining that some temporary image cannot be found

I've no idea how to solve this problem

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

sounds all very strange.

This works for me in Sikuli X:

def myFind(image):
 find(image).highlight(2)

myFind("sikulilogo.png")

If you like, just zip the .sikuli folder and send it to my mail at https://launchpad.net/~raimund-hocke

Revision history for this message
Petr Fejfar (pf1957) said :
#6

> If you like, just zip the .sikuli folder and send it to my mail

Sent.

Thx, pf

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

ok, I did not have any problems, the images were found in the def().

So your problem really is, that the images are not found in the context of the clicks in the def().

I opened the .html in my browser, to have something to find and used the following modified script running it in slow motion:

Settings.MoveMouseDelay = 0.25

def enter_geco_return(acode,aimage):
 #click( )
 #type(acode)
 #click( )
 #click( )
 #click( )
 hover(aimage)
 #click( )
 #click( )

#################################################

# book in return of Geco Tabak, branch Breclav Hypernova, seal code 999
enter_geco_return("999", "i.png")
enter_geco_return("998", "0405.png" )

exit()

Revision history for this message
Petr Fejfar (pf1957) said :
#8

> I opened the .html in my browser, to have something to find and used the following modified
> script running it in slow motion:

I did the same and it works for me as well...

Finally, I've found the bug: the key problem was the misinterpretation of the stack trace info
bellow:

> org.sikuli.script.FindFailed: FindFailed: i.png can't be found.

This error does not mean that *file* i.png cannot be found, but that a match of image *itself* cannot be found,
because I used wrong image in preceeding click() command

Maybe a wording of the error above could be changed to something like this: "no match of i.png found"

Thx for your help and great tool, pf

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

That's good.

I will post a request bug, since I think, the feedback could be a little bit clearer.

with X 1.0rc2, the FindFailed concept is revised and an optional interaction with a prompt is added.