当我们使用 sikuli 有多个复选框时如何 select 特定文本复选框

How to select particular text checkbox when we have multiple checkbox using sikuli

我在 Adob​​e Live Cycle 表单中有 5 个水平复选框。我导入了 Sikuli 罐子来支持硒代码。我已经编写了一部分 Sikuli 代码并从 Selenium 测试用例调用。

我面临的问题是:

例如,

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

我想第一次查卡,后来我要换现金,支票,DD等。

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

如果我捕捉带有文本的图像,它会点击中心的 ,所以它只是点击文本而不是复选框..

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

有人遇到过类似的问题并对此有任何解决方案吗?

谢谢, 钱德拉

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

您可以使用 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());
            }
        }
}

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

可以找到 JavaDoc API 的文档 here

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