【问题标题】:Sikuli - Click on element does not work with Java API but it works from IDE - WPF appSikuli - 单击元素不适用于 Java API,但它适用于 IDE - WPF 应用程序
【发布时间】:2015-01-27 22:13:09
【问题描述】:

我正在评估用于测试基于 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());
                }
        }

我做错了什么?

【问题讨论】:

    标签: java automated-tests sikuli


    【解决方案1】:

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

    屏幕屏幕 = new Screen(); 模式pattern = null;

        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);
            }
        }
    

    【讨论】:

      【解决方案2】:

      在我的情况下,我有两台显示器似乎是个问题..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-07
        • 1970-01-01
        • 2019-03-20
        相关资源
        最近更新 更多