如果图像出现在区域内,则结束循环
End loop if image appears inside region
如果某个图像出现在某个区域内,我试图让我的脚本结束循环或退出。
我在 运行 脚本时遇到错误;我不确定哪里出了问题,因为关于 stopregion
和 stopimage
的部分是另一个人建议的。
错误:
[error] TypeError ( 'tuple' object is not callable )
我的代码如下:
Image1 = ("1453735625632-12.png")
Image2 = ("1453723117924-16.png")
stopRegion = (815,423,314,136)
stopImage = ("1454946335394.png")
while True:
click(wait("1453202630435-1.png",FOREVER))
if stopRegion.exists("1454946335394.png", 0): # ends in error
break
click(wait("1453994048404-9.png",FOREVER))
click(wait("1453202812250-3.png",FOREVER))
while True:
print('Searching....')
if exists("1453723117924-17.png", 0):
click("1453723117924-18.png")
# Break loop.
break
if exists("1453735625632-14.png", 0):
click("1453735625632-15.png")
# Break loop.
break
click(wait("1453202882292-7.png",FOREVER))
非常感谢任何帮助。
我觉得问题是
stopRegion = (815,423,314,136) # this is a tuple, not a Region
stopRegion.exists("1454946335394.png", 0) # a tuple does not have an .exists method
试试看
stopRegion = Region(815,423,314,136)
你还需要修改缩进,我建议给图片起更有意义的名字,比如
BUTTON1 = "1453994048404-9.png"
BUTTON2 = "1453202812250-3.png"
RESULT_A = "1453723117924-17.png"
RESULT_A_BUTTON = "1453723117924-18.png"
RESULT_B = "1453735625632-14.png"
RESULT_B_BUTTON = "1453735625632-15.png"
START = "1453202630435-1.png"
STOP = "1454946335394.png"
FINISHED = "1453202882292-7.png"
stop_region = Region(815,423,314,136)
done = False
while not done:
print("Starting search")
click(wait(START, FOREVER))
if stop_region.exists(STOP, 0):
print("Found STOP")
break
click(wait(BUTTON1, FOREVER))
click(wait(BUTTON2, FOREVER))
while True:
print('Searching....')
if exists(RESULT_A, 0):
print("Found RESULT_A")
click(RESULT_A_BUTTON)
# finished searching
done = True # set flag to exit outer while loop
break # leave inner while loop
if exists(RESULT_B, 0):
print("Found RESULT_B")
click(RESULT_B_BUTTON)
# go to next search
break # leave inner while loop but not outer one
click(wait(FINISHED, FOREVER))
如果某个图像出现在某个区域内,我试图让我的脚本结束循环或退出。
我在 运行 脚本时遇到错误;我不确定哪里出了问题,因为关于 stopregion
和 stopimage
的部分是另一个人建议的。
错误:
[error] TypeError ( 'tuple' object is not callable )
我的代码如下:
Image1 = ("1453735625632-12.png")
Image2 = ("1453723117924-16.png")
stopRegion = (815,423,314,136)
stopImage = ("1454946335394.png")
while True:
click(wait("1453202630435-1.png",FOREVER))
if stopRegion.exists("1454946335394.png", 0): # ends in error
break
click(wait("1453994048404-9.png",FOREVER))
click(wait("1453202812250-3.png",FOREVER))
while True:
print('Searching....')
if exists("1453723117924-17.png", 0):
click("1453723117924-18.png")
# Break loop.
break
if exists("1453735625632-14.png", 0):
click("1453735625632-15.png")
# Break loop.
break
click(wait("1453202882292-7.png",FOREVER))
非常感谢任何帮助。
我觉得问题是
stopRegion = (815,423,314,136) # this is a tuple, not a Region
stopRegion.exists("1454946335394.png", 0) # a tuple does not have an .exists method
试试看
stopRegion = Region(815,423,314,136)
你还需要修改缩进,我建议给图片起更有意义的名字,比如
BUTTON1 = "1453994048404-9.png"
BUTTON2 = "1453202812250-3.png"
RESULT_A = "1453723117924-17.png"
RESULT_A_BUTTON = "1453723117924-18.png"
RESULT_B = "1453735625632-14.png"
RESULT_B_BUTTON = "1453735625632-15.png"
START = "1453202630435-1.png"
STOP = "1454946335394.png"
FINISHED = "1453202882292-7.png"
stop_region = Region(815,423,314,136)
done = False
while not done:
print("Starting search")
click(wait(START, FOREVER))
if stop_region.exists(STOP, 0):
print("Found STOP")
break
click(wait(BUTTON1, FOREVER))
click(wait(BUTTON2, FOREVER))
while True:
print('Searching....')
if exists(RESULT_A, 0):
print("Found RESULT_A")
click(RESULT_A_BUTTON)
# finished searching
done = True # set flag to exit outer while loop
break # leave inner while loop
if exists(RESULT_B, 0):
print("Found RESULT_B")
click(RESULT_B_BUTTON)
# go to next search
break # leave inner while loop but not outer one
click(wait(FINISHED, FOREVER))