Unable to match the image using "exists" method

Asked by Vinoth

Hi there,

I tried sikuli to handle browser Authentication pop up. I am able to enter the username and password in authentication pop up. But the problem that i am facing now is unable to match the image using exists method.

I need to compare multiple images (say: There will be 'A', 'B', 'C' images) if A does not exists, It has to match the image of B and C. When is the condition is satisfied, it has to do appropriate action.

Code:
import org.sikuli.basics.SikuliScript;
import org.sikuli.script.*;
import org.sikuli.*;

public class AuthenticationHandler {

 public static void main(String[] args) {
        Screen s = new Screen();

            try{
     Match b= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1410953555965.png");
     Match c= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1410952744291.png");
     Match d= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1410953428209.png");
     Match a= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1410953400598.png");
     Match e= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1411044859010.png");
                          Match f= s.find("D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/1411044859011.png");

 if(s.exists(a)!=null)
      {
      System.out.println("1st");
      s.type(b,"clinique");
      s.type(c,"dfdsf");
       s.click(d);
      }
     else if(s.exists(e)!=null)
      {
      System.out.println("2nd");
       s.type(b,"mac");
       s.type(c,"asdssa");
        s.click(d);
      }
                      else if(s.exists(f)!=null)
                            {
      System.out.println("3rd");
       s.type(b,"mac");
       s.type(c,"asdssa");
        s.click(d);
      }

        }
        catch(FindFailed e){
                e.printStackTrace();
        }
}

}

Problem here is Always the first condition is entered. Because exists method returns some value even the appropriate image is not displayed on the screen. What would be the best alternative for exists method or How can be the exists method used to solve my problem.

Please answer my question at the earliest.

Thanks,
Vinoth

Question information

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

early enough ??? LOL

In your program there are some problems:

- if one of the find() ops crash, your exists switch will never be entered (the catch block is executed)
- a, b, c, … are all Match objects, but exists() must be run with an image
- the find() are not necessary in this setup

this is my suggestion:

import org.sikuli.script.*;
public class AuthenticationHandler {
 public static void main(String[] args) {
  Screen s = new Screen();
  String dir = "D:/ScriptFiles/Workspace/SikuliTest/src/Authentication/";
  String b = dir + "1410953555965.png";
  String c = dir + "1410952744291.png";
  String d = dir + "1410953428209.png";
  String a = dir + "1410953400598.png";
  String e = dir + "1411044859010.png";
  String f = dir + "1411044859011.png";
  try {
   if (s.exists(a) != null) {
    System.out.println("1st");
    s.type(b, "clinique");
    s.type(c, "dfdsf");
    s.click(d);
   } else if (s.exists(e) != null) {
    System.out.println("2nd");
    s.type(b, "mac");
    s.type(c, "asdssa");
    s.click(d);
   } else if (s.exists(f) != null) {
    System.out.println("3rd");
    s.type(b, "mac");
    s.type(c, "asdssa");
    s.click(d);
   }
  } catch (FindFailed ff) {
   ff.printStackTrace();
  }
 }
}

Revision history for this message
Vinoth (vinoth2017) said :
#2

Hi Raiman,

Thanks for replying. Still first condition only is getting entered even it fails the condition.

The problem is with 'exists' method. Because it does return some value even the image is not displayed. Hence the first conditions is never failed.

Please revert back.

Thanks in advance
Vinoth

Revision history for this message
Vinoth (vinoth2017) said :
#3

 if (s.exists(a) != null) It goes null never. Even the image is not displayed or image (e) is displayed.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

what version of Sikuli do you use?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

exists() definitely returns null, if the image cannot be found in the specified region.

If it does not return null and the image is not visible, then it has found something else similar.

Please consult the docs, how to use Pattern().similar() to increase the needed similarity score to avoid false positives.

BTW:

   if (s.exists(a) != null) {
    System.out.println("1st");
    s.getLastMatch().highlight(2)

will reveal, what was found and in the log message you can see the similarity score.

Can you help with this problem?

Provide an answer of your own, or ask Vinoth for more information if necessary.

To post a message you must log in.