title: Python Selenium Webdriver - Try except loop
body: <p>I'm trying to automate processes on a webpage that loads frame by frame. I'm trying to set up a <code>try-except</code> loop which executes only after an element is confirmed present. This is the code I've set up:</p>
  
  <pre><code>from selenium.common.exceptions import NoSuchElementException
  
  while True:
      try:
          link = driver.find_element_by_xpath(linkAddress)
      except NoSuchElementException:
          time.sleep(2)
  </code></pre>
  
  <p>The above code does not work, while the following naive approach does:</p>
  
  <pre><code>time.sleep(2)
  link = driver.find_element_by_xpath(linkAddress)
  </code></pre>
  
  <p>Is there anything missing in the above try-except loop? I've tried various combinations, including using time.sleep() before <code>try</code> rather than after <code>except</code>.</p>
  
  <p>Thanks</p>