How to check in sikuli that image is exist in screen or not and perform if else condition on that result

RAHUL VP picture RAHUL VP · Nov 24, 2017 · Viewed 12.8k times · Source

I am trying to automate a desktop application in sikuli. What i am doing copying data from from existing user and creating new user using some of that data. In form there are two check boxes. If that check boxes is ticked for existing user, then while creating new user i need to check the text box. for that am taking checked text box image and giving in if condition. If checked text box image is there in that page i will carry value 1 to a variable else value will be 0. according to that value am performing check uncheck function in new user creation page. But the issue what i am facing is, am not able to check if the image exist in that page or not in sikuli. Please anybody help me. my code is giving below

 int bomanager=0;
            int boswitchboard=0;

            System.out.println("boswitchboard value before assign it to 1" + bomanager);
            if  (screen.exists("images/backofficeswitchboardwithtick.png") != null)
            {   
                boswitchboard=1;
                System.out.println("boswitchboard value after assign"+boswitchboard);
            }

            System.out.println("bomanager value before assign it to 1" + bomanager);
            if(screen.exists("images/backofficemanagerwithtick.png") != null)
                {
                    bomanager=1;
                    System.out.println("bomanager value after assign it to 1"+bomanager);
                }

then using this value need to perform below function.

System.out.println("Before condition" + bomanager);
            if (bomanager ==0){
                screen.click("images/backofficemanagerwithtick.png");

            }

            screen.setAutoWaitTimeout(10);

            System.out.println("Before condition" + boswitchboard);

            if(boswitchboard==0){
                System.out.println("Inside To tick Condition" + boswitchboard);
                System.out.println("Ticking the SwitchBorad when itsnot already ticked");
                screen.click("images/backofficeswitchboardwithtick.png");

            }

Answer

anish picture anish · Nov 24, 2017

I'm asssuming you're looking to use "if exists" method here

if exists(img, timeout): click(img) else: ....