当我们使用sikuli

时间:2018-03-27 04:53:17

标签: sikuli

我在Adobe Live Cycle表单中有5个水平复选框。我已经进口了Sikuli罐以支持硒代码。我写了一部分Sikuli代码,并从Selenium测试案例中调用。

我面临的问题是:

例如,

 _        _        _
|_| Card |_| Cash |_| Check 

我想第一次检查卡,随后的时间,我必须更改现金,支票,DD等。

如果我在sikuli中单独捕获Checkbox,则总是选择First Checkbox作为卡片。

如果我使用文本捕获图像,它会点击中心的图像,所以它只是单击文本而不是复选框..

无论如何我可以做到这一点..我看过几个使用目标偏移(http://doc.sikuli.org/tutorials/checkone/checkone.html)的例子,但由于我使用的是Sikuli jar,我猜不可能。

有人可能遇到类似的问题,并为此有任何解决方案吗?

谢谢, 钱德拉

1 个答案:

答案 0 :(得分:1)

这是一个可能的解决方案:

您可以尝试使用 findAll()查找屏幕中所有复选框的巧合。然后,将坐标保存到列表中,然后单击并单击它们。让我举个例子:

package test;

import java.awt.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import java.awt.event.InputEvent;
import org.sikuli.script.Finder;
import org.sikuli.script.Match;
import org.sikuli.script.Region;
import org.sikuli.script.*;
import org.sikuli.script.ImageLocator;

public class Test {

        public static void main(String args[]) throws AWTException, FindFailed {
            // Define 2 list to get X and Y
            List <Integer> x = new ArrayList<>();
            List <Integer> y = new ArrayList<>();
            Test t = new Test();
            t.getCoordinates(x,y);
            t.clickOnTarget(x,y);
        }

        public void clickOnTarget(List <Integer> x, List <Integer> y) throws AWTException {
            Robot r = new Robot();

            for (int i = 0; i < x.size(); i++) { // From 0 to the number of checkboxes saved on X list
                r.mouseMove(x.get(i), y.get(i));
                r.delay(500);
                r.mousePress(InputEvent.BUTTON1_MASK); //Press click
                r.mouseRelease(InputEvent.BUTTON1_MASK); // Release click
                r.delay(5000);
                // And your code goes here
            }
        }

        public void getCoordinates(List <Integer> x, List <Integer> y) throws FindFailed {
            ImagePath.add("D:\\workplace\\test\\img\\");
            Screen s = new Screen();
            Iterator <Match> matches = s.findAll(new Pattern("CheckBoxImg.png").similar(0.9f)); // Get all coincidences and save them
            Match archivo;
            Location l;
            while (matches.hasNext()) { 
                Match m = matches.next(); // Get next value from loop
                l = new Location(m.getTarget()); // Get location
                // Add to the list of coordinates
                x.add(l.getX());
                y.add(l.getY());
                System.out.println("Coordinates: x: "  + l.getX() + " y: " + l.getY());
            }
        }
}

如您所见,您不需要返回两个列表。只在函数getCoordinates中设置它们并填充它们。

可以找到JavaDoc API的文档here

我希望它会对你有所帮助。我投入了一个小时的生命: - )