How To Input a variable containing text to reg.find()

Asked by Mark McGuinn

Trying to create a script which passes from excel to Sikul a name and then searches on an application screen for that name. The screen has 50 visible icons with a different name in each. I am trying to find the icon which matches the name passed in and click it. However when using the following code I get an error:

 reg=Region(303,294,1078,530)
m = reg.find("FORD")

[error] RunTimeIDE: ImageMissing: FORD
[error] RunTimeIDE: Wait: Abort: Jython: at xcel1 (49)
[error] script [ xcel1 ] stopped with error at line --unknown--

If I pass an image in it works, but not passing either hard coded text or a variable with the text. SO the question is how can I pass just a text string to the reg.find() command?

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

Do you use SikuliX1.1.4 or SikuliX2.0?
You have to use findText instead of find.
https://sikulix-2014.readthedocs.io/en/latest/news.html#revision-of-the-text-find-api

Revision history for this message
Mark McGuinn (mmcguinn) said :
#2

Hi,

thanks for the feedback. I had been using 1.1.3 because I could not get the side tab with the various coding shortcuts to work in v2. If I try to run the script in v2.0.1 I get a strange problem in that the ide will move the mouse to the correct point on the screen but will not click as it is supposed to. This is he first step in the script so I cannot confirm the solution until I can reach that point in the test script.

If there is something which is stopping the script from clicking in v2 would you let me know. Below is the code

#
Settings.OcrTextSearch=True
Settings.OcrTextRead=True
# Open a spreadsheet and read values
def openAppleMenu(event):

    import java.lang.System
import java.lang.Object
import java.awt.event.InputEvent
carmake = "Ford"
Env.addHotkey(Key.F1, KeyModifier.ALT+KeyModifier.CTRL,openAppleMenu)

click("1575150169419.png")
wait("1575150442463.png")

Revision history for this message
masuo (masuo-ohara) said :
#3

Please check option setting, if you use SikuliX1.1.3 .
[allow searching for text] check box may be off.

Open Preferences Window
[File]-[Preference]

Open Preferences:more Options...
[more options...]

Switch on [allow searching for text] check box.

Revision history for this message
Mark McGuinn (mmcguinn) said :
#4

Did as suggested and am still getting an error:

[error] RunTimeIDE: ImageMissing: FORD
[error] RunTimeIDE: Wait: Abort: Jython: at Mensel (20)
[error] script [ Mensel ] stopped with error at line --unknown--

This is where I pass a hard coded string to the find command

reg = Region(300,293,1083,535)

m = reg.find("FORD")

Revision history for this message
masuo (masuo-ohara) said :
#5

Switch on [allow searching for text] check box.
And restart SikuliX IDE.

If that doesn't work, I don't know any more.

Revision history for this message
Mark McGuinn (mmcguinn) said :
#6

Have managed to get somewhere with v2.0.1. Now getting to the point where it does the findText but it fails with an error even though the text is in the image:

Code

reg = Region(300,293,1083,535)

m = reg.findText(carmake)

print m

Error
[error] script [ Mensel ] stopped with error in line 25
[error] FindFailed ( FORD as text )
[error] --- Traceback --- error source first
line: module ( function ) statement
25: main ( <module> ) m = reg.findText(carmake)
[error] --- Traceback --- end --------------

Revision history for this message
Launchpad Janitor (janitor) said :
#7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.