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

问题描述 投票:2回答:2

我试图在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");

            }
sikuli
2个回答
3
投票

我很想你在这里使用“if exist”方法

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


2
投票

使用方法exists()我通常使用:

if(exists("yourUrlImage")!=null) (do something when exists) else (do another thing when not exists)

导致返回“匹配”对象。

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.