0

i am hitting an error for the code below, this is my first time running eclipse with sikuli to automate desktop application. the image is an icon of a new folder in desktop. any help?

import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
public class skulix {

    public static void main(String[] args) throws FindFailed {

        Screen screen = new Screen();
        Pattern pattern = new Pattern("C:\\Users\\User\\Desktop\\a\\a.PNG");
        screen.click(pattern);  
    }
}

this is the error i am hitting.

[error] RunTimeINIT: *** BE AWARE: Running on Java 8+ *** Please report problems ***
Exception in thread "main" FindFailed: C:/Users/User/Desktop/a/a.PNG: (94x97) in S(0)[0,0 1920x1080] E:Y, T:3.0
  Line 2761, in file Region.java

    at org.sikuli.script.Region.wait(Region.java:2761)
    at org.sikuli.script.Region.find(Region.java:2326)
    at org.sikuli.script.Region.getLocationFromTarget(Region.java:3220)
    at org.sikuli.script.Region.click(Region.java:3718)
    at org.sikuli.script.Region.click(Region.java:3703)
    at testscript.skulix.main(skulix.java:18)

reference image taken and used - error message

[error] RunTimeINIT: *** BE AWARE: Running on Java 8+ *** Please report problems ***
[error] RunTimeAPI: Problematic lib: C:\Users\User\AppData\Roaming\Sikulix\SikulixLibs_201807110819\VisionProxy.dll (...TEMP...)
[error] RunTimeAPI: VisionProxy.dll loaded, but it might be a problem with needed dependent libraries
ERROR: ...TEMP...: Can't load IA 32-bit .dll on a AMD 64-bit platform
[error] RunTimeAPI:  *** terminating: problem with native library: VisionProxy.dll

using 2.0.4 jar. error message

Exception in thread "main" FindFailed: C:\Users\User\Desktop\a\2.png: (68x83) in R[0,0 1920x1080]@S(0)
  Line 2287, in file Region.java

    at org.sikuli.script.Region.find(Region.java:2287)
    at testscript.skulix.main(skulix.java:13)
  • take reference image using silkuli it self, the error means silkuli cannot find the pattern or image – PDHide Apr 27 at 7:06
  • ok, i've tried it, seems to have some issue. the error updated on my main post – user1579414 Apr 27 at 7:16
  • are you using Maven ? – PDHide Apr 27 at 7:39
  • yes the script is running on maven eclipse – user1579414 Apr 27 at 7:57
  • github.com/RaiMan/SikuliX1/blob/master/README.md , try using the latest version 2.1.0-SNAPSHOT or 2.0.4 – PDHide Apr 27 at 8:06
1

The below code works:

    //open the url
    driver.get("https://www.facebook.com");
    Screen screen = new Screen();

    //##################### ONE TIME STEP STARTS ###############################

    //A overlay screen will apear that asks you to take the screen shot
    // select the area you want to capture
    ScreenImage scrImgFile = screen.userCapture();
    Pattern pattern = null;

    //THis method will save the file to the current directory
    String path = scrImgFile.getFile(".");

    //This will print the full path of the save file
    System.out.println("Please note down the file Path: ");
    System.out.println(path);

    //  rerun the program by replacing the below path with the path we got above

    //##################### ONE TIME STEP ENDS ###############################

    pattern = new Pattern("D:\\selenium_poc_java\\Selenium_basic\\.\\sikuliximage-1588144437209.png");

    try {
        screen.click(pattern);
    } catch (FindFailed e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Code explanation:

  1. We capture the element image using the interactive mode of silkuli (userCapture())
  2. We save the capture to current directory, the file name is generated randomly (getFile()
  3. Note down the file path printed
  4. Replace the path in pattern with the file path printed, Remove the code block between one time step starts and one time step ends. Rerun the code

Output

If you use Pattern(Path) then you can click any element realtime:

enter image description here

For clicking Desktop applications (or any folder):

Clcik properties and goto general tab, copy the location and paste it in Desktop.getDesktop().open(new File("C:\\Users\\user\\Desktop"));

     Screen screen = new Screen();

    //import java.awt.Desktop;
    Desktop.getDesktop().open(new File("C:\\Users\\user\\Desktop"));

    //##################### ONE TIME STEP STARTS ###############################

    //A overlay screen will apear that asks you to take the screen shot
    // select the area you want to capture
    ScreenImage scrImgFile = screen.userCapture();
    Pattern pattern = null;

    //THis method will save the file to the current directory
    String path = scrImgFile.getFile(".");

    //This will print the full path of the save file
    System.out.println("Please note down the file Path: ");
    System.out.println(path);

    //  rerun the program by replacing the below path with the path we got above

    //##################### ONE TIME STEP ENDS ###############################

    pattern = new Pattern(path);

    try {
        screen.click(pattern);
    } catch (FindFailed e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  


}

Update:

you can use App.open("C:\\Users\\user\\Desktop"); also to open the desktop insted of using awt. This is much faster that awt.

import org.sikuli.script.App;
| improve this answer | |
  • FindFailed: C:\Users\User\Downloads\a\sikuliximage-1588172361517.png: (72x100) in R[0,0 1920x1080]@S(0) Line 2222, in file Region.java , hi thanks for the help. the one time step works, however, i still hitting the error. after i replace with one time step method. – user1579414 Apr 29 at 15:09
  • Try adding a sleep before the click – PDHide Apr 29 at 15:13
  • pattern = new Pattern(path); try like this and see if the code actually works – PDHide Apr 29 at 15:14
  • @user1579414 Added GIF showing how i selected the radio button and it clicked radio button – PDHide Apr 29 at 16:47
  • added 5sec sleep and having same error.. i'm trying automate click an shortcut in my desktop which is a notepad txt... – user1579414 Apr 30 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.