title: How to detect if frame is no longer active after main page redirect in Selenium
body: <p>I'm trying to grab data from an ugly javascript-only website. The main content that I'm looking for is in an <code>iframe</code>. I'm using <code>webdriver.Chrome</code>.</p>
  
  <p>My course of action:</p>
  
  <ol>
  <li>Load page with <code>driver.get(url)</code></li>
  <li>Switch to iframe</li>
  <li>Locate element inside iframe</li>
  </ol>
  
  <p>The problem is that the main page may (or may not) be redirected/refreshed <strong>after</strong> I switched to iframe, and the scope will become "full page" again. </p>
  
  <pre><code>driver.get(url)
  
  # switch to iframe
  WebDriverWait(driver, timeout).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "frame_id")))
  
  # PARENT PAGE MAY BE REFRESHED AT THIS POINT
  
  WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "element_id"))) 
  </code></pre>
  
  <p>What could be done is this situation? </p>
  
  <p>I'm thinking if there is a way to "subscribe" to redirect events, so every time the page reloads, a callback will be called. Then I could switch to iframe again.</p>
  
  <p>Or maybe there is a way to wait until all redirects are completed?</p>