For the past few months, I have been using Selenium to automate a very boring but essential part of my job which involves uploading forms.
Recently, the site has implemented a feed back survey which randomly pops up and switches the driver to a new frame. I have written the code which can handle this pop up and switch back to my default frame however the issue is with the randomness.
Is there a way to run my popup handling code as soon the exception generated by the wrong frame is thrown?
I could encase my whole script in a try and except block but how do I direct the script to pick back up from where it left off?
Any advice is much appreciated!
I have encountered a similar kind of situation. 
My recommendation to you is speak to your front end devs or the company which provides the feedback survey and ask them for a script to disable the pop-ups for a browser session that you run. 
Then, execute the script using selenium library(like JavascriptExecutor) as soon as you open the web page so that you do not see the random occuring pop-ups.
Selenium Python - How to handle a random pop up?