Save stack context during debugging

Maybe a noob question: I’m writing to write a script to click on a calendar notification. Right after performing that click, a new dropdown menu pops up for like 5 secs. Its very hard for me to inspect the details of all the menu items to write a script to select what I want. Is there a way to save the context of the entire stack and ui elements in those 5 secs so that I can analyze after?