title: Python, Selenium : 'Element is no longer attached to the DOM'
body: <p>I am scraping a website, <a href="http://www.lipperleaders.com/" rel="nofollow">www.lipperleaders.com</a>. I want to extract the funds detail of Singapore. I have successfully implemented drop-down selection and extracted the content of the first page appearing after submission of the options. But when I try to go to next pages (by making the code to click next button) I am getting error <code>'Element is no longer attached to the DOM'</code>. </p>
  
  <p>My code is about 100 lines but I can give a general idea of the flow of execution of my code:</p>
  
  <pre><code>...                    # creating driver object and all the imports
  def main():
      ...
      result = find_elements_by_tag_name('span')  
      ...
      driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
      main()
  main()
  </code></pre>
  
  <p>This code works fine for the 1st page but when <code>main()</code> is called again after clicking of the next button. Before this recursive method, I also tried putting this inside a loop, then also same error. </p>
  
  <p>And if I write the same code like:</p>
  
  <pre><code># some code
  result = find_elements_by_tag_name('span')  
  driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
  # some code
  driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
  .
  .
  </code></pre>
  
  <p>This code works fine w/o any error the next page loads and executes the code written after that. But I cannot write the  same <code>driver.find_element_by_id().click()</code> for 500 pages, even I will have to repeat the rest of the code associated with each page. That's why I am trying for loop or recursion, but its not working for me.</p>
  
  <p>Please let me know what is the problem with my approach.</p>