title: Using try statements when sorting through frames
body: <p>So I have multiple dynamic frames that have names that change depending on what elements are being clicked. I've tried using <code>try</code> statements like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  try:
      driver.switch_to.frame(driver.find_element_by_xpath("//*[@id='ui-id-1']/iframe"))
  except:
         try:
           driver.switch_to.frame(driver.find_element_by_xpath("//*[@id='ui-id-4']/iframe"))
         except:
              try:
                  driver.switch_to.frame(driver.find_element_by_xpath("//*[@id='ui-id-7']/iframe"))
              except:
                     print("Failed to find a frame")
  
  </code></pre>
  
  <p>However as soon as I pass over the first frame it will never find the second frame (in this case id-4).</p>
  
  <p>I've also tried finding frames by using src:</p>
  
  <pre><code>element = driver.find_element_by_css_selector('[src*="text-within-frame"]')
  driver.switch_to.frame(element)
  
  </code></pre>
  
  <p>What am I do wrong/what should I be doing differently?</p>
  
  <p>EDIT:</p>
  
  <p>Ok so when I run through the program it will always get to the first frame, access and scrape all the data I need, and then fail once it tries to move on to the next frame area to scrape. I think the issue is that once Frame 1 exists it always finds Frame 1 even if it is no longer there and the new data I need is on Frame 2 (id-4 in my case). Is there a way where I can have my code disregard Frame 1 once it is used?</p>
  
  <p>Here is an explanation of what I need in a non-code accurate way to hopefully help explain a bit better.:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  Switch to Frame 1
  
  if Frame 1 already used:
       Switch to Frame 2
            if Frame 2 already used:
               Switch to Frame 3
  </code></pre>