如何检查sikuli图像是否存在于屏幕中,并对该结果执行if else条件

时间:2017-11-24 05:56:05

标签: sikuli

我正在尝试在sikuli中自动化桌面应用程序。我正在做什么从现有用户复制数据并使用一些数据创建新用户。在表单中有两个复选框。如果勾选现有用户的复选框,则在创建新用户时我需要选中文本框。因为这是采取选中的文本框图像和给予条件。如果检查文本框图像在那个页面中,我将值1携带到一个变量,否则值将为0.根据该值在新用户创建页面中执行check uncheck功能。但是我面临的问题是,我无法检查图像是否存在于sikuli中。请有人帮助我。我的代码在下面给出

 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);
                }

然后使用此值需要执行以下功能。

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");

            }

2 个答案:

答案 0 :(得分:3)

我很想你正在寻找使用"如果存在"这里的方法

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

答案 1 :(得分:2)

使用方法if(exists("yourUrlImage")!=null) (do something when exists) else (do another thing when not exists) 我通常使用:

{{1}}

导致返回“匹配”对象。

希望这会有所帮助

相关问题