【问题标题】:Why won't sikuli script click on the image?为什么 sikuli 脚本不能点击图片?
【发布时间】:2014-04-04 18:17:49
【问题描述】:

我对 sikuli 完全陌生,并尝试对图像屏幕截图执行简单的点击操作,这对我来说已成为一门火箭科学。

仅供参考 - 我截取了谷歌徽标并将其保存在我的机器上。但是,如果我获取实际的 google 徽标图像 url,那么脚本就可以工作。

这是使用图片截图的正确方法吗?

public class TestGenericButton {
    public static void main(String[] args) throws MalformedURLException {
        // Open the main page of Google Code in the default web browser
        browse(new URL("http://code.google.com"));

        // Create a screen region object that corresponds to the default monitor in full screen 
        ScreenRegion s = new DesktopScreenRegion();

        // Specify an image as the target to find on the screen
        //URL imageURL = new URL("http://code.google.com/images/code_logo.gif");
        URL imageURL = new URL("img\\google.gif");
        Target imageTarget = new ImageTarget(imageURL);

        // Wait for the target to become visible on the screen for at most 5 seconds
        // Once the target is visible, it returns a screen region object corresponding
        // to the region occupied by this target
        ScreenRegion r = s.wait(imageTarget,5000);

        // Display "Hello World" next to the found target for 3 seconds
        Canvas canvas = new DesktopCanvas();
        canvas.addLabel(r, "Hello World").display(3);

        // Click the center of the found target
        Mouse mouse = new DesktopMouse();
        mouse.rightClick(r.getCenter());
    }
}      

【问题讨论】:

  • 你看到的错误是什么?

标签: java sikuli


【解决方案1】:

不,这不是创建 ImageTarget 的方法。您在文件中有要使用的图像,因此您需要传递 File,而不是 URL

the documentation,而不是

    URL imageURL = new URL("img\\google.gif");
    Target imageTarget = new ImageTarget(imageURL);

    File imageFile = new File("img\\google.gif");  // assumes your working directory is set right...
    Target imageTarget = new ImageTarget(imageFile);

【讨论】:

    【解决方案2】:

    提供图片URL,这个方法应该做点击部分:)

    private void click(String image) throws FindFailed{
    
        Screen screen = new Screen();
    
        Pattern pattern = new Pattern(image).similar((float) 0.7);
    
        if(screen.find(pattern)!=null){ 
            screen.mouseMove(pattern); 
            screen.click(pattern); 
        }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-03-07
      • 2016-07-16
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 2012-03-01
      • 2012-02-02
      • 1970-01-01
      • 2022-11-23
      相关资源
      最近更新 更多