Feb-28-2019, 12:02 PM
Hey!
So I wrote a long code which is using the pyautogui locatonOnScreen and then center and then click functions. Basically it has a picture of a button which it finds on screen and clicks there. I have around 40 of these in the code to find specific buttons in a program. My problem is that sometimes the script goes too fast and it already tries to search for the image even though technically it has not appeared yet. We are talking about fractions of a second but randomly it give me the "picture not found" error depending on how fast my computer is at the moment and where the code gets to.
So my question is, can I somehow tell the whole code to use "time.sleep(3)" (wait 3 seconds before proceeding) if it encounters and error during the code and continue from the same line without adding a "try and else" after every line?
So I wrote a long code which is using the pyautogui locatonOnScreen and then center and then click functions. Basically it has a picture of a button which it finds on screen and clicks there. I have around 40 of these in the code to find specific buttons in a program. My problem is that sometimes the script goes too fast and it already tries to search for the image even though technically it has not appeared yet. We are talking about fractions of a second but randomly it give me the "picture not found" error depending on how fast my computer is at the moment and where the code gets to.
So my question is, can I somehow tell the whole code to use "time.sleep(3)" (wait 3 seconds before proceeding) if it encounters and error during the code and continue from the same line without adding a "try and else" after every line?