title: Python Selenium: how to switch frames after navigation?
body: <p>I'm trying to download a link within a table after navigating to a page using Python3 + selenium.  After using selenium to click through links, and inspecting the elements on the latest-loaded page, I can see that my element is within a frame called "contents".  When I try to access this frame, however, upon calling:</p>
  
  <pre><code>DRIVER.switch_to_frame("contents")
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>selenium.common.exceptions.NoSuchFrameException: Message: contents
  </code></pre>
  
  <p>To gain more context I applied an experiment.  Both the page that I loaded using DRIVER.get(URL) and the one to which I navigated had a frame called "menu".<br>
  I could call DRIVER.switch_to_frame("menu") on the first page, but not on the second. </p>
  
  <pre><code>DRIVER = webdriver.Chrome(CHROME_DRIVER)
  DRIVER.get(SITE_URL)
  DRIVER.switch_to_frame("contents") # This works
  target_element = DRIVER.find_element_by_name(LINK)
  target_element.click()
  time.sleep(5)
  DRIVER.switch_to_frame("menu")
  target_element = DRIVER.find_element_by_name(LINK2)
  target_element.click()
  target_element = DRIVER.find_element_by_name(LINK3)
  target_element.click()
  DRIVER.switch_to_frame("contents") # Code breaks here.
  target_element = DRIVER.find_element_by_xpath(REF)
  target_element.click()
  print("Program complete.")
  </code></pre>
  
  <p>I expect the code to find the xpath reference for the link in the "contents" frame.  Instead, when attempt to switch to the "contents" frame, python run-time errors and cannot find "contents".</p>