Textsearch instead of finding screenshots

Asked by snick3rs

Hi,

i am facing an interesting issue on Linux Ubuntu 14.04

I have to explain, that i had Sikuli 1.0.1 before trying to set up Sikuli 1.1.0 beta2. So i am now back on Sikuli 1.0.1.

I wrote some test code, but i get an error message, that text search is currently switched off - instead of searching the screenshot:

import org.sikuli.script.*;
public class TestClass {

 public static void main(String[] args) {

        Screen s = new Screen();
        String imgPath = "/home/snick3rs/workspace/SikuliXTest/src/images/";
        Pattern firefox = new Pattern(imgPath + "firefoxAddressBar.png").similar((float) 0.85);

        try {
         App.open("/usr/bin/firefox");
                s.wait(firefox, 10);
                s.type("l", Key.CTRL, 0);
                s.type(null, "www.google.com", 0);
                s.type(null, Key.ENTER, 0);
        }
        catch(FindFailed e) {
                e.printStackTrace();
        }

   }

}

This should open Firefox and type the URL and then press Enter. But it does not work.

Any idea how i can fix that?

Thanks in advance.

Greetings,
Mat

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
snick3rs
Solved:
Last query:
Last reply:
Revision history for this message
snick3rs (snick3rs030) said :
#1

I have the same issue on Windows 7 - 32 Bit. The error messages i get in eclipse are:

Jul 04, 2014 8:42:02 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[log] App.open C:/Program Files/Mozilla Firefox/firefox.exe(3840)
[error] Region.find(text): text search is currently switched offFindFailed: Text search currently switched off
  Line 1671, in file Region.java

 at org.sikuli.script.Region.wait(Region.java:1671)
 at org.sikuli.script.Region.find(Region.java:1590)
 at org.sikuli.script.Region.getLocationFromTarget(Region.java:1991)
 at org.sikuli.script.Region.click(Region.java:2197)
 at org.sikuli.script.Region.keyin(Region.java:2718)
 at org.sikuli.script.Region.type(Region.java:2695)
 at TestClass.main(TestClass.java:14)

Any idea?

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

this happens, because the imagefile
imgPath + "firefoxAddressBar.png"

cannot be found in the filesystem at runtime.

Revision history for this message
snick3rs (snick3rs030) said :
#3

Hi RaiMan,

thanks for your message. I checked again the image path. The image file is definitely there. Also i copied the image file to another folder in my user directory (/home/username/). I get an other error message, that the image file "null" could not be found in the file system. I have no idea, what is wrong, because the image files are saved in the correct directories (folder). I am wondering, because this worked 3 weeks ago with my first installation of Sikuli 1.0.1. It does not with my 2nd installation on linux. On Windows 7 it is the first installation of Sikuli 1.0.1 in a virtual machine.

Greetings
Mat

Revision history for this message
snick3rs (snick3rs030) said :
#4

I have set up a fresh installation of Sikuli 1.0.1 (sikuli-script.jar) on my laptop with Windows Vista 32-bit, using the same environment (eclipse, JDK, ...) and i have the same problem like on linux ubuntu 14.04 and on Windows 7:

[error] Text search is currently switched off...

I really don't know what is wrong, because the directories exist as well as the image files. It does not matter in what directory the image files are saved, i always get the same error message.

Is sikuli-script.jar corrupt in a way?

Please help.

Thanks.

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

I just tested on Windows 8 with 1.0.1 and sikuli-java.jar (setup option 3) (should make no difference to your Windows setup)

This worked as expected in my Eclipse:

package my.Test;

import java.io.File;
import java.io.IOException;

import org.sikuli.basics.Debug;
import org.sikuli.script.*;

public class Run {

 public static void main(String[] args) throws FindFailed, IOException {
  Debug.setDebugLevel(3);
  String wd = System.getProperty("user.dir");
  Debug.log(0, "Running in: %s", wd);
  Screen s = new Screen();
// absolute file path, taken as is
  File img = new File(wd, "images\\1404636229697.png");
  Debug.log(0, "Image absolute: %s exists: %s", img, (img.exists() ? "YES" : "NO"));
  Pattern pimg = new Pattern(img.getAbsolutePath());
  s.find(pimg).highlight(2);
// relative filepath, searched in working folder
  img = new File("images\\1404636229697.png");
  Debug.log(0, "Image relative: %s exists: %s", img, (img.exists() ? "YES" : "NO"));
  pimg = new Pattern(img.getPath());
  s.find(pimg).highlight(2);
 }
}

The folder images is at the root level of the project folder.

I do not see any reason, why this should not work on Linux too.

Revision history for this message
snick3rs (snick3rs030) said :
#6

I used Debug.setDebugLevel(3); in my script and found out that the problem was this line of code:

s.type("l", Key.CTRL, 0);

So, i changed it to s.type("l", Key.CTRL); and this works.

Thanks again for your time and help :-)

Greetings Mat