Click() function fails to click on image name passed to it parameter of list element

Asked by Hitesh

I want to be able to pass certain parameters to sikuli script such as images to be clicked on or text to be typed from a "config" file as this information can vary from person to person. When I try to do so in my script, I keep getting "FindFailed(Text Search currently switched off)" error. However, I have included "Settings.OcrTextSearch = True" in the script. I have provided part of the code below. If additional info is needed, please contact me.

#code
Settings.OcrTextSearch = True
Settings.OcrTextRead = True

#open the config file and read the contents
fin = open("C:\Users\Administrator\Desktop\Sikuli\configure_iOS_MX.txt", "r")
lines = fin.readlines()
fin.close()
n = 0
var = [ ]
for line in lines:
   var.append(line)
   n = n + 1

click(var[0])

The script fails here and gives the error message provided above. "var[0]" contains the name of the image file located in same directory as the sikuli script. eg: "img1.png" (including double quotes). Moreover, I have also checked on the "allow searching for text" and "allow OCR" in the "Preferences: more options" for Sikuli. I am using Sikuli IDE 1.0.1 on Windows 2008 64 bit system. Please reply asap as until this issue gets resolved, I can't proceed further. Thanks.

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

Understanding right?

you read image filenames from the file, to use them for click()?

If yes, has nothing to do with text feature.

An image file name e.g. img1.png is simply a string, so in your case var[0] should contain img1.png
(same as after saying vary[0] = "img1.png")

--- using the text feature:
Did you install with option 5?
Is tessdata folder missing complained?
If yes, delete the libs folder in the setup folder to get it recreated on rerun of Sikuli including the needed tessdata stuff.

Revision history for this message
Hitesh (kapur68) said :
#2

I did not have tessdata folder missing message. I have installed with option 5. The issue is still there.

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

You did not answer my first question/assumptions from comment #1, but anyway:

a problem might be, that line and hence var[n] still contains a newline "\n" at the end of the string.
The usual approach to get rid of whitespace is:

var.append(line.strip())

Revision history for this message
Hitesh (kapur68) said :
#4

Getting rid of white space did not help.

I am reading image filename from the file. However, this time when I reinstalled Sikuli along using option 1 and 5, although I did not get any error messages, when I reran the script, it did give me following error message:

[error] TextRecognizer: init: tessdata folder not found at C:/Users/Administrator/Desktop/Sikuli1/libs/
[error] Region.find(text): text search is now switched off

Following is the modified code:

with open("C:\Users\Administrator\Desktop\Setup_and_Config\iOS_MX1.txt", "r") as f:
    for line in f:
        line1 = line.strip()
        match = re.search ('^(\w*:)\s(.*)', line1)

       if (match.group(1) == "hkwin2k8ins:"):
            relayName = match.group(2)

click(relayName)

I am using Sikuli IDE 1.0.1 on Windows 2008 platform

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

--- [error] TextRecognizer: init: tessdata folder not found at C:/Users/Administrator/Desktop/Sikuli1/libs/
this error together with the fact, that you selected option 5, means, you want to use text search.

Wether this is true or not: delete the libs folder in ..../Sikuli1 and rerun to get the libs folder recreated with the Tesseract stuff (this is an inconvenience in 1.0.1)

--- click(relayName)
the error situation means, that the content of relayName is not taken as an image file name or the given image file is not found in the image path.
There should be more information on that before the above error message.

So you should check the content of relayName at the time of click.

Revision history for this message
Hitesh (kapur68) said :
#6

I have checked the relayName. It is the same as the image file name. I have made sure to have the image located in the same folder as the other images used in that script. Following are all the error traces:

[error] TextRecognizer: init: tessdata folder not found at C:/Users/Administrator/Desktop/Sikuli1/libs/
[error] Region.find(text): text search is now switched off
[error] script [ Setup_iOS_MX2 ] stopped with error in line 32
[error] FindFailed ( Text search currently switched off )

Earlier today, I tried reinstalling the sikuli (pack1 and pack5), but I kept on getting unable to download sikuli-ide.jar file error and then the installation would stop. I have reported this as a bug:

#1246467 Unable to install Sikuli IDE on Windows 2008 (64 bit)

So, I have not been able to install pack5 but then again you say that it is only needed for working with text and I am not doing that. So, right now, the question boils down to is this: Is Sikuli truly capable of doing what I am trying to do? That is, pass the image file name to click on from a text file. It is necessary to do so to make it easier for various testers to use the same script without having to customize it too much as the information that varies from tester to tester can be provided to the script from a config file.

I greatly appreciate your efforts to help me so far. If you at all think that this is a limitation in Sikuli then please inform me about that as well.

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

--- install Sikuli-IDE
see faq 2363

--- Is Sikuli truly capable of doing what I am trying to do?
Of course it is.
If you provide image filenames programmatically, you must make sure:
- that these filenames are valid Sikuli image filenames
- that these image files are found on the image path

In your case, you should set up a separate image directory and use setBundlePath(), to point to that folder (this directory could even be the first line in your file, so you could have different sets of images).

In your script put a
print relayName

before the click to get the used filename printed before the error.

The above message is ok, if your intention is not to search for text instead of images.
In the Preferences you should switch off the text options, so the error message would be shorter.

In your version of Sikuli and earlier, Sikuli tried to find the given string as text on the screen, if the given string did not make up a valid filename or the file was not found on the image path.

this is a valid image filename on Windows:
a string containing: some-path-relative-or-absolute\some-name.png
if you only use some-name.png, the image will be searched in the script bundle and on the image path (if any is setup).

So again check your filenames.

Can you help with this problem?

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

To post a message you must log in.