Sikuli / Python中的循环问题

时间:2014-11-06 05:37:27

标签: python sikuli

不知道我哪里出错:

mm = list(r.findAll(rButton))# find all rButtons on main screen
print len(mm) #check how many are detected
for x in range(0,len(mm)):
    r.click(mm[x])
    if(not r.exists(rButtonDisabled)):
        print "this is a test"
        r.wait(BeginTask,FOREVER)
        r.click(BeginTask)
        r.wait(rButton,FOREVER)
    else: click(Cancel)

有2个屏幕。我们称之为主屏幕和screen2。在主屏幕上有相同的按钮,rButton。我想找到所有可见的rButton,然后开始点击它们。理想情况下,我希望它点击第一个rButton,它将它带到screen2,如果屏幕2上的按钮被禁用,点击取消将我们移回主屏幕,然后转到主屏幕上的第二个rButton,这再次带我们到画面2。根据主屏幕上的rButton,可以禁用或启用screen2上的按钮。

我的代码没有达到这个效果。不知道我哪里出错了。

1 个答案:

答案 0 :(得分:2)

我不确定你是如何定义Region' r'但是默认情况下,Sikuli不会在操作系统原生的屏幕外搜索。您需要首先让sikuli找到另一个屏幕,然后定义该屏幕的边界。

现在看来,你正在搜索Region' r'无论你想要什么屏幕......你应该分别定义两个屏幕,或者Sikuli不知道切换屏幕来寻找你想要的按钮。例如,您可以使用Screen类来定义哪个屏幕 -

numScreens = getNumberScreens()
r = SCREEN #in all caps, this is the reserve word for the whole screen native to the OS
    #can also use r = Screen(0)
if numScreens > 0 #make sure second screen was counted by sikuli
    r2 = Screen(1).getBounds() 
else: raise the appropriate error

#Here's your code with some adjustments for multiple monitors
#on main screen
mm = list(r.findAll(rButton))# find all rButtons on main screen
print len(mm) #check how many are detected
for x in range(0,len(mm)):
    r.click(mm[x])
    #on secondary screen
    if(not r2.exists(rButtonDisabled)):
        print "this is a test"
        r2.wait(BeginTask,FOREVER)
        r2.click(BeginTask)
        #back to main screen
        r.wait(rButton,FOREVER)
    #click the cancel button on secondary screen
    else: r2.click(Cancel) # <-- the defining region was missing here in your original code

Here's关于多监视器环境的Sikuli文档