不知道我要去哪里错了:

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,如果禁用了screen2上的按钮,则单击“取消”将我们移回主屏幕,然后转到主屏幕上的第二个rButton,这又使我们转到屏幕2。根据主屏幕上的rButton,可以禁用或启用screen2上的按钮。

我的代码无法达到这种效果。不知道我要去哪里错了。

最佳答案

我不确定您如何定义Region'r',但是默认情况下,Sikuli不会在OS本身的屏幕之外进行搜索。您需要首先让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文档

关于python - Sikuli/Python中的循环问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26772419/

10-12 16:41