【问题标题】:How to make the script stop at specified time?如何让脚本在指定时间停止?
【发布时间】:2013-10-09 20:20:22
【问题描述】:

我有 100 个软件列表。 我有这个代码:

doubleClick("1380765362298.png")
wait(0.01)
#mouseDown(Button.LEFT)
#mouseUp(Button.LEFT)
while exists("1380774111845.png",10):
    click("1380774111845.png")
    wait(0.01)
    mouseDown(Button.LEFT)
    mouseUp(Button.LEFT)
    wait(2)
#except:
    #pass
    try:
        click("1380765740907.png")
        wait(3)
        waitVanish("1380772439126.png",FOREVER)
    except:
        pass
    try:
        click("1380769537610.png")
        wait(4)

    except:
        pass
    try:
        click("1380772563891.png")
        wait(2)
    except:
        pass
    try:
        type(Key.DELETE)
        wait(2)
    except:
        pass
    try:
        click("1380774317204.png")
        wait(1)
    except:
        pass
else:
    pass

在这段代码中,我试图让它循环到 10 点,但它不起作用。 它会一直循环,直到所有软件都运行完毕。 那么我怎样才能让它循环到 10 点呢?

【问题讨论】:

  • 你想做10次哪件事?
  • 只运行 1380774111845.png 10 次
  • 您希望在 10 秒后结束?
  • @theBigChalk 不是 10 秒。我的意思是 10 次循环。
  • 我从来没有使用过 sikuli,但是文档说:exists(PS[, seconds]) 检查给定模式是否在屏幕上可见。参数: PS – 一个 Pattern 对象或一个字符串(图像文件的路径或纯文本) seconds – 一个数字,可以有一个分数,以秒为单位的最大等待时间。内部粒度为毫秒。如果未指定,则使用 Region.setAutoWaitTimeout() 设置的自动等待超时值。使用常数 FOREVER 等待无限时间。所以我们讨论的是 while 循环中的秒数,而不是时间。

标签: python python-2.7 sikuli


【解决方案1】:

只要 1380774111845.png 在屏幕上,您的 while 循环就会执行。如果只希望它执行 10 次,请将 while 替换为 for 循环:

for x in range(10):
   if not exists("1380774111845.png",10):
       break

另外,删除最后的 else/pass,因为它是不必要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-10
    • 2018-06-28
    • 1970-01-01
    • 2018-06-14
    • 2017-03-18
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多