如何使用Sikuli长时间等待按钮,中间可能还有一些维护任务?

sak*_*atc 3 automation wait sikuli

我有一个网页,我正在等待按钮出现,当它出现时,我想点击它.该按钮位于计时器上,可能需要一个小时才能显示.此外,如果按钮花费的时间超过一定时间,我想移动鼠标(否则网站会自动将我注销).

所以,等待按钮出现我设计了这个Sikuli脚本:

button = "button.png"

while(1):
    if exists(button):
        print("found it")
        click(button)
        break
    else:
        print("wait longer")
        wait(button,30*60)
        # do a regular task

print "all done!"
Run Code Online (Sandbox Code Playgroud)

以上似乎没有功能.如果按钮在屏幕上,脚本将找到它...但是,如果它必须等待它将只是快速超时FindFailed异常(click()即使屏幕上不存在该按钮).我考虑过写一个处理程序,但看起来有点矫枉过正.

我做错了什么,等待这么长时间的视觉事件的最佳方法是什么?

小智 6

对你有一些其他的想法......

 while(1):
 wait(Button, 30*60) # This will spinlock for 30 minutes for the button to appear
 if exists(Button):
     hover(Button) # Debug statement allowing user to see what Sikuli has matched to
     click (Button)
 else:
     mouseMove(Location(50,100))
     mouseMove(Location(50,200))
Run Code Online (Sandbox Code Playgroud)

链接:


Ale*_*gna 5

也许Sikuli会识别看起来很像你的按钮,并尝试点击它.如果右键单击IDE中的按钮模式,则可以微调公差级别以进行识别.尝试在按钮周围精确切割图像,并将值增加到更精确.

我建议你阅读本教程
http://doc.sikuli.org/tutorials/surveillance/surveillance.html
并设置一个事件处理程序来管理你的按钮
http://doc.sikuli.org/region. html#Region.onAppear
http://doc.sikuli.org/region.html#observingvisualeventsinaregion
写的代码不多.

您可以在Sikuli的博客中获得完整源代码的一个很好的例子 http://sikuli.org/blog/2011/08/15/sikuli-plays-angry-birds-on-google-games/

我想你可以设置你的处理程序并继续使用

观察(永远)