Can't click when using a Match object - JAVA

Asked by Joe Taylor

I'm needing to click on multiple of the same image my only problem is when I'm trying to click a match the mouse is just clicking and not moving to the coordinates of the images found. The match iterator is able to find all the images but its just not moving to them. I've tried a couple of tests with different images but its not working... Any help is appreciated.

My code:

import java.util.Iterator;

import org.sikuli.script.FindFailed;
import org.sikuli.script.Match;
import org.sikuli.script.Screen;

public class TestClick {
 static String greenTile = "C://Java//greenTile.png";
 static String yellowTile = "C://Java//yellowTile.png";
 static String purpleTile = "C://Java//purpleTile.png";
 static String blueTile = "C://Java//blueTile.png";

 public static void main(String[] args) throws InterruptedException {
  Screen s = new Screen();
  Iterator<Match> matches = null;
  while (true) {
   try {
    matches = s.findAll(greenTile);
    for (; matches.hasNext(); matches.next()) {
    try {
     s.click(matches);
     Thread.sleep(1000);
    } catch (FindFailed e) {
     e.printStackTrace();
    }
   }
   } catch (FindFailed e) {
    e.printStackTrace();
   }

   Thread.sleep(5000);
  }

 }

}

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
Best Eugene S (shragovich) said :
#1

I afraid this is not how it works.

What you are trying to do is to click the Iterator<Match> object while what you really need to do is click on each one of the found elements (if any). Try something like this:

ImagePath.setBundlePath("C:/temp/sikulipatterns/");
Screen s = new Screen();

Iterator<Match> results = s.findAll("eclipseDocIcon.png");

while (results.hasNext()) {
    Match currentMatch = results.next();
    currentMatch.highlight(1); //this helps to visualize the process and better understand what elements have been found
    currentMatch.click();
}

Revision history for this message
Joe Taylor (joetaylor12589) said :
#2

Thanks Eugene S, that solved my question.