For loop not breaking in java

Asked by Jeremiah Jacquet

I am trying to delete rows in a queue via an iOS app. I press edit and the trash icon appear, and then I have sikuli select those icons to remove. Seems pretty straight forward and sikuli is really good at doing that . The trick in my case is that the list is dynamic and I never know how many rows will be visible in that queue so I created a For loop in java.

The loop does not seem to be breaking, Here is my code:

 @Test
 public void testDeleteTrashIcon() throws Exception {

  for (int i = 0; i < 10; i++) {

   s.wait("imgs/TrashIcon.png", 10);
   s.click("imgs/TrashIcon.png", 0);

   if (s.exists("imgs/ConfirmDeletionOfTrashIcons.png", 0) != null) {
    break;
   }
  }
 }

So here is the scenario in this one instance:
-there is a 2 rows displaying trash icon
-the loop I have set can delete up to 10
- the method above does not recognize the IF statement in the loop and gives me "FindFailed: can not find imgs/TrashIcon.png because its still trying to finish all 10

can someone tell me where I have written this incorrectly? or another way to have sikuli loop until another image appears using java?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

This simply means, that s.exists("imgs/ConfirmDeletionOfTrashIcons.png" returns null, which means, the image is not found.

Might be a timing problem (takes time for the "imgs/ConfirmDeletionOfTrashIcons.png" to appear.

try this:

@Test
 public void testDeleteTrashIcon() throws Exception {

  for (int i = 0; i < 10; i++) {

   s.click(s.wait("imgs/TrashIcon.png", 10), 0); //saves one search

   if (s.exists("imgs/ConfirmDeletionOfTrashIcons.png", 1) != null) { //adjust wait time accordingly
    break;
   }
  }
 }

Revision history for this message
Jeremiah Jacquet (jeremiahjacquet) said :
#2

Thanks RaiMan, that solved my question.