Getting as ERROR saying - ".png looks like a file, but can't be found on the disk. Assume it's text."

Asked by Astro

Hi,

I am calling a function that is present in b.sikuli from a.sikuli.
the function in b.sikuli is as follows:
function():
    popup("i am in download items")
    click("Downloaded.png")

when i am calling the function,i am able to get the popup message but unable to click on the image(where image exists and clickable for sikuli).
Here is the error message i am getting:
[error] Downloaded.png looks like a file, but can't be found on the disk. Assume it's text.

Note: i am able to click on the image, when i execute that particular statement(click("Downloaded.png")) in a new sikuli file.

Please help me in resolving this issue.

Thanks & Regards,
Astro

Question information

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

Supposing you are using import according to the recommendations in
http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images

then you should have:

# a.sikuli
import b
#...
b.function

#b.sikuli
from sikuli import *
def function():
   popup()
   click("Downloaded.png")

If this is correct, then the image file Downloaded.png should either be in the folder a.sikuli or b.sikuli.

The above message tells you, that Sikuli cannot find the image file neither in a.sikuli nor in b.sikuli (so it takes it as a text to be searched).

Revision history for this message
Astro (bheeram) said :
#2

Hi RaiMan,

Thanks for your quick response, with the error message i understood that sikuli is unable to find the image, so i have cross checked it and found that the Download.png is present in b.sikuli only. and my code contains the import statement as mentioned above.
So is there anything we can debug the issue?

Thanks & Regards,
Astro

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

--- found that the Download.png
but Sikuli looks for a "Downloaded.png" --- a typo?

--- So is there anything we can debug the issue?
into b.sikuli put a print statement:

from sikuli import *
print "b.sikuli is imported"
def function():
# ....

This will print the message once, when the <import b> statement is processed the first time in the IDE (you have to restart the IDE, if you change anything in imported scripts or use reload() look the docs link above).

If on Windows: take care, that the scripts are stored at least one level below root and that the path does not contain any special characters or blanks/underscores.

Revision history for this message
Astro (bheeram) said :
#4

Hi RaiMan,

regarding Downloaded.png, its a typo
And i am using Windows.... here is my code,

#exp1.sikuli
import exp2
from exp2 import *
function()

#exp2.sikuli
from sikuli import *
def function():
    popup("i am in function")
    click("Downloaded.png")

and the "Downloaded.png" is present in exp2.sikuli. When i ran the exp1.sikuli, i am able to get the popup message but unable to click on the respective image, which is actually present.
Here is the error message i am getting now : org.sikuli.script.FindFailed: FindFailed: can not find Downloaded.png on the screen.

Note: When i clicked on the Downloaded.png(in sikuli) , i am able to see the red color highlight in the matching preview tab.

Please let me know, what the problem might be... ?

Thanks & Regards,
Astro

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

Ok, now Sikuli finds the image file, but does not find the image itself on the screen during 3 seconds after the click action is started to be processed (FindFailed Exception).

So it might be, that the popup() by steeling the focus from your app, makes the app to change something in its appearance, so that the similarity drops below 0.7 (which leads to not found).

I suggest to change the popup into a print or just delete it and run the script again (maybe using the low motion mode).

Another option is, to capture the image with as little background around as possible and concentrate the image on the cetral specifics.

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

BTW:
when using
from xyz import *

then another
import xyz

is not needed

Revision history for this message
Astro (bheeram) said :
#7

as per your suggestions, i have changed the code. please check it !!!!

#exp1.sikuli
from exp2 import *
function()

#exp2.sikuli
from sikuli import *
def function():
    print "i am in function"
    click("Downloaded.png")

Here is the output error i got...

i am in function

[error] Stopped
[error] An error occurs at line 2
[error] Error message: Traceback (most recent call last):
 File "C:\Users\reddysre\AppData\Local\Temp\sikuli-tmp3692390715012185730.py", line 2, in
 function()
 File "C:\Users\reddysre\Desktop\Automation\PC\exp2.sikuli\exp2.py", line 4, in function
 click("Downloaded.png")
 Line 2, in file C:\Users\reddysre\AppData\Local\Temp\sikuli-tmp3692390715012185730.py

 at org.sikuli.script.Region.wait(Region.java:501)
at org.python.proxies.sikuli.Region$Region$0.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: File Downloaded.png not exists
 Line 2, in file C:\Users\reddysre\AppData\Local\Temp\sikuli-tmp3692390715012185730.py

Please note that the print statement is getting excuted but not the click statement, please let me know what can i do further.

Thanks & Regards,
Astro

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

the image is not found on the screen in that moment. I cannot tell you why.

Are you sure, it is visible on the screen at the time your script runs?

If you are sure, put this as 2nd line in exp1.sikuli:
print find("Downloaded.png")

Might be worth a try, to capture a new version of the image.

Revision history for this message
Astro (bheeram) said :
#9

I have found the resolution,

When i copied the image to exp2.sikuli, my script got worked....

may i know why my script is searching for that image in exp2 instead of exp1(it is the sikuli file where screenshot has been taken).
is there a process of changing that ? because i thought of calling the functions in exp2 by keeping the function definitions in exp1, so i cant copy every image to exp1.sikuli folder.
Please note that i am using windows7.

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

Uuuups, yes - this is a bug.

Because each imported script is put on the image path, all images in imported scripts are found all over the place.

But the images in the main script are found through bundle path, which is not on the image path.

Try adding this at the beginning of your main script:

p = getBundlePath() # images of main
if not p in (list(getImagePath())): addImagePath(p)

this will add your main scripts image path to the global image path.

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

Uuuups, yes - this is a bug.

Because each imported script is put on the image path, all images in imported scripts are found all over the place.

But the images in the main script are found through bundle path, which is not on the image path.

Try adding this at the beginning of your main script:

p = getBundlePath() # images of main
if not p in (list(getImagePath())): addImagePath(p)

this will add your main scripts image path to the global image path.

Can you help with this problem?

Provide an answer of your own, or ask Astro for more information if necessary.

To post a message you must log in.