Wait for Button to Finish and Select Main Page

Alright guys I cant figure out the best plan of action for this scenario I am facing. If you click the following link:

You will see two problems as outlined:

  1. When I click the “Close” button, it turns into thinking; however, I was wondering what I could add to the code to not time out until, let’s say, the Cancel button is no longer present as “Close” becomes thinking and there isn’t a Cancel button anywhere else?

  2. The next issue is focusing back on the page. I was wondering if there was another way to focus back on the main page without selecting the tab by name or position. Is their an easier way?

Does this work for you: Wait for image to DISappear