简体   繁体   English

“图像无效,但 TextSearch 已关闭!” 错误 - Mac 上的 Sikuli

[英]"Image not valid, but TextSearch is switched off!" error - Sikuli on Mac

I am trying to automate a desktop application on Mac using Sikuli and Eclipse.我正在尝试使用 Sikuli 和 Eclipse 在 Mac 上自动化桌面应用程序。

Source code:源代码:

import org.sikuli.script.FindFailed;
import org.sikuli.script.ImagePath;
import org.sikuli.script.Screen;

public class TextEditorExample {

public static void main(String[] args) throws FindFailed {
 // TODO Auto-generated method stub
Screen s=new Screen();
System.out.println(ImagePath.getBundlePath());
 s.click("spotlight_icon.png");
 s.find("spotlight.png");
 s.type("spotlight.png","finder");
 s.click("applications.png");
 s.click("texteditor_icon.png");
 s.find("texteditor.png");
 s.type("texteditor.png","Sikuli Example");

 }
}

But I'm getting the following error :但我收到以下错误:

[error] Image: Image not valid, but TextSearch is switched off!
[error] RunTimeAPI: Wait: Abort: unknown
[error] RunTimeAPI: ImageMissing: spotlight_icon.png

Path of sikuli script: sikuli脚本的路径:

  /Users/adamin/Desktop/Automation/SikuliExample/src/TextEditorExample.java

Path of Images:图片路径:

/Users/adamin/Desktop/Automation/SikuliExample/src/spotlight_icon.png
/Users/adamin/Desktop/Automation/SikuliExample/src/spotlight.png
/Users/adamin/Desktop/Automation/SikuliExample/src/applications.png
/Users/adamin/Desktop/Automation/SikuliExample/src/texteditor_icon.png
/Users/adamin/Desktop/Automation/SikuliExample/src/texteditor.png

Can anybody help me in solving this issue?有人可以帮我解决这个问题吗?

The imagepath is set by default to your project root folder and will only look for patterns there.图像路径默认设置为您的项目根文件夹,并且只会在那里寻找模式。 Just set the bundle path manually to wherever your files are:只需手动将包路径设置为文件所在的位置:

ImagePath.setBundlePath("fullpath");

Alternatively, place your files to whatever folder that is returned by:或者,将您的文件放置到由以下返回的任何文件夹中:

System.out.println(ImagePath.getBundlePath());

Use Pattern.使用模式。

Pattern pattern = new Pattern(path+"spotlight_icon.png");
Screen s=new Screen();
        try {
            s.click(pattern);
        } catch (FindFailed e) {
            e.printStackTrace();
        }

This Error most probably comes when image is not loadable, Meanwhile, use this approach当图像不可加载时,很可能会出现此错误,同时,使用此方法

try{
    String path = "path of your image";
    Pattern target = new Pattern(path);
    Screen scr = new Screen();
    scr.click(target);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

Y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM