Reputation: 4318
I have 5 Horizontal check boxes in Adobe Live Cycle forms. I have imported Sikuli jars to support for selenium code. I have written a portion of Sikuli code and calling from Selenium Test case.
The problem which i am facing is:
Eg.,
_ _ _
|_| Card |_| Cash |_| Check
I wanted to check first time Card, and the subsequent times, i have to change Cash, Check, DD etc.
If I capture Checkbox alone in sikuli, always it selects First Checkbox which is card.
If I capture image with Text, it clicks on the on the center, so it is just clicking the text and not checkbox..
Is there anyway I can do this.. I have seen few examples to use Target offset (http://doc.sikuli.org/tutorials/checkone/checkone.html) but since I am using Sikuli jar, it is not possible I guess.
Can someone faced the similar kind of problem and have any solution for this?
Thanks, Chandra
Upvotes: 0
Views: 778
Reputation: 411
Here is a possible solution:
You could try to find all the coincidences of checkbox in the screen, using findAll(). Then, save the coordinates into lists and after that, order and click them. Let me show you an example:
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());
}
}
}
As you can see, you don't need to return both Lists. Only set them in the function getCoordinates and it will fill them.
The documentation for JavaDoc API can be found here
I hope it will help you. I invest an hour of my life :-)
Upvotes: 1