Region.findText(): Finding text with Java API

Asked by Jeff Hall

I'm a little bit unclear on the status of the Region.findText() method in the SikuliX version 1.1.1 Java API.

There is documentation for this method:

https://raiman.github.io/SikuliX-2014/javadocs/org/sikuli/script/Region.html#findText-java.lang.String-double-

...and it appears to be implemented in the Region class:

https://github.com/RaiMan/SikuliX-2014/blob/develop/API/src/main/java/org/sikuli/script/Region.java#L2858

However, I noticed an answer (and related FAQ) that seems to indicate that the findText() method is not actually implemented:

https://answers.launchpad.net/sikuli/+question/248501

I'm asking about the status because it doesn't seem to work as expected with my code, something like this:

public static boolean findTextInDocument(Screen s, String text) {
        boolean textFound = false;

        try {
            s.findText(text, 2000);
            textFound = true;
        } catch (FindFailed e) {
            e.printStackTrace();
        }

        return textFound;
    }

Can anyone confirm that the findText() method should (or should not) work with the version 1.1.1 API?

Question information

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

yes, works as it should (tested ;-)

--- because it doesn't seem to work as expected with my code
... what exactly?

Revision history for this message
Jeff Hall (oldjoe) said :
#2

Thanks for the confirmation RaiMan!

The problem must be on my end. I keep getting a NullPointerException from the screen.findText() method in the following example class, but haven't been able to figure out why just yet...

public class DummyTest {

    private static Screen screen = new Screen();

    @BeforeClass
    public static void setup() {
        Settings.OcrTextSearch = true;
        Settings.OcrTextRead = true;
        screen.setAutoWaitTimeout(10);

        // Open Microsoft Word application
        screen.type(Key.ESC, Key.CTRL);
        screen.type("winword");
        screen.type(Key.ENTER);

    @AfterClass
    public static void tearDown() {
        // Close Microsoft Word
        screen.type(Key.F4, Key.ALT);
        screen.type("n");
    }

    @Test
    public void experimentWithText() {
        String text = "This is my favorite text string.";
        screen.type(text);

        try {
            screen.findText(text);
        } catch (FindFailed findFailed) {
            findFailed.printStackTrace();
        }

    }

}

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

Just tested on 1.1.2 --- works.

anything to see in the stack trace about the exception source?

Revision history for this message
Jeff Hall (oldjoe) said :
#4

Aaagh, user error! Causing myself grief with typos.

Once I got that sorted out, the Region.findText() method is indeed working as described.

Thanks for your help RaiMan, and thanks for all your work on SikuliX.

Revision history for this message
Christian Böhm (chbohm) said :
#5

I do have the same issue... what did you do to sort this out?