【问题标题】:How to select particular text checkbox when we have multiple checkbox using sikuli当我们使用 sikuli 有多个复选框时如何选择特定的文本复选框
【发布时间】:2018-03-27 04:53:17
【问题描述】:

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

我面临的问题是:

例如,

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

我第一次想查卡,以后要换Cash、Check、DD等。

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

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

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

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

谢谢, 钱德拉

【问题讨论】:

    标签: sikuli


    【解决方案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找到

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

    【讨论】:

    • 感谢您的帮助。
    • 不客气!让我告诉你; TargetOffset 可在 Sikuli java api 获得。您可以通过我在答案末尾提供的链接找到它=)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2017-11-26
    • 2020-10-12
    相关资源
    最近更新 更多