title: Python, Selenium: how to refresh page until element is present
body: <pre><code>while True:
      try:
          browser.find_element_by_xpath('//*[@id=&quot;layoutPage&quot;]/div[1]/div/div/div[3]/div[4]/div[2]/div/section/div[1]/div/button/div')
          break
      except NoSuchElementException:
          browser.refresh()
  </code></pre>
  <p>Why do I still get <code>selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {&quot;method&quot;:&quot;xpath&quot;,&quot;selector&quot;:&quot;//*[@id=&quot;layoutPage&quot;]/div[1]/div/div/div[1]/div/div[1]/button[2]&quot;}</code> eroor?
  I have imported the <em>NoSuchElementException</em> from <em>selenium.common.exceptions</em>.</p>