Sikuli - 单击元素不适用于Java API,但它适用于IDE - WPF应用程序



我正在评估用于测试基于 WPF 的应用程序的工具。我目前正在尝试使用Java API的Sikuli。当我尝试从 Java 代码中单击对象时,鼠标光标会转到该对象并突出显示该对象,但是单击操作不起作用,因为预期的菜单没有打开。不过,click() 方法返回状态 1。如果我从Sikuli IDE单击,它可以正常工作。我尝试了 1.0.1 版本以及每晚构建。这是我的代码:

@Test
     public void testLogin() {
             Screen s = new Screen();
                try {
                        s.wait(Constants.overflowMenu);
                        System.out.println(s.click(Constants.overflowMenu));
                        s.wait(Constants.signInMenuOption, 5);
                } catch (FindFailed e) {
                        Assert.fail(e.getMessage());
                }
        }

我做错了什么?

试试这段代码,它对我有用。 它做什么,它会检查图像,单击它,然后在屏幕上再次检查此图像,如果它仍然存在,请再次单击。

屏幕

屏幕 = 新屏幕(); 模式模式 = 空;

    try
    {
        pattern = new Pattern(imageLocation);
        screen.wait(pattern,30);
        screen.click(pattern);
        System.out.println("First Attempt To Find Image.");
    }
    catch(FindFailed f)
    {
        System.out.println("Exception In First Attempt: " +f.getMessage());
        System.out.println("FindFailed Exception Handled By Method: ClickObjectUsingSikuli. Please check image being used to identify the webelement. supplied image: " +imageLocation);
        Assert.fail("Image wasn't found. Please use correct image.");
    }
    Thread.sleep(1000);
    //In case image/object wasn't clicked in first attempt and cursor stays in the same screen, then do second atempt.
    if(screen.exists(pattern) != null)
    {
        try
        {
            screen.getLastMatch().click(pattern);
            System.out.println("Second Attempt To Find Image.");
            System.out.println("Object: " +imageLocation + " is clicked successfully.");
        }
        catch(FindFailed f)
        {
            System.out.println("Exception In Second Attempt: " +f.getMessage());
            System.out.println("FindFailed Exception Handled By Method: ClickObjectUsingSikuli. Please check image being used to identify the webelement. supplied image: " +imageLocation);
        }
    }

就我而言,这似乎是我有两个显示器的问题。

相关内容

最新更新