I don't know if you've solved your problem or if my suggestion will help your situation, but when I look at your code I see some risky assumptions that you are making. I run into situations similar to yours all the time, with programs that behave oddly, and here's how I would try to address the problem. Instead of running the action to press the button as you do, I would first write code to wait until the button appears, and then press (repeatedly, with a short pause for safety) until it disappears. Something like this:
This approach is a safer way to press a button, but it doesn't even take into account some situations like handling timeouts. So when I write code as simple as pressing a button, and I want to do it reliably, sometimes the code to press the button can be a full page in size.
In the future I plan to use subroutines to press buttons like this. My subroutine would probably look something like this:
The error message could perhaps be sent as an SMS message to my Apple Watch, if I wanted to see my error handling messages when I'm away from home.
I didn't upload this code because I didn't test it, and because it's too trivial to upload.