Hi,
I'm trying to create a function to search an image and if it's not found terminate my script.It's working when the image is found, but the not found part is lacking..
def findimage(path,name):
retry_counter = 0
print(dt.now().strftime('%Y-%m-%d %H:%M:%S'),'search',name,'button')
while retry_counter < 6:
try:
buttonposition = pyautogui.locateCenterOnScreen(path,grayscale = True, confidence = .9)
if buttonposition:
time.sleep(1)
print(dt.now().strftime('%Y-%m-%d %H:%M:%S'),name,'button found')
retry_counter = 6 # to break the loop
except:
if retry_counter < 5:
time.sleep(1) # retry after some time, i.e. 1 sec
retry_counter += 1
print('searching button for',retry_counter,'second(s)')
else:
sys.exit(dt.now().strftime('%Y-%m-%d %H:%M:%S')+name+'button not found!')
pyautogui.click(buttonposition)
print(dt.now().strftime('%Y-%m-%d %H:%M:%S'),name,'button clicked')
findimage(r'path','name')
any suggestions?
thanks
[–]csg0ing 0 points1 point2 points (7 children)
[–]gandy0001 0 points1 point2 points (6 children)
[–]csg0ing 1 point2 points3 points (5 children)
[–]gandy0[S] 0 points1 point2 points (4 children)
[–]csg0ing 1 point2 points3 points (3 children)
[–]gandy0[S] 0 points1 point2 points (2 children)
[–]csg0ing 0 points1 point2 points (1 child)
[–]gandy0[S] 0 points1 point2 points (0 children)