title: Calling a function inside 'For' loop throws a NameError
body: <p>I'm trying to call a function from a FOR loop but get the error:</p>
  
  <pre><code> test()
  NameError: name 'test' is not defined
  </code></pre>
  
  <p>The code is given below: </p>
  
  <pre><code>from selenium import webdriver
  from selenium.common.exceptions import NoSuchElementException
  from selenium.webdriver.common.keys import Keys
  import time
  from lxml import html
  import requests
  import xlwt
  
  browser = webdriver.Firefox() # Get local session of firefox
  
  # 0 wait until the pages are loaded
  browser.implicitly_wait(3) # 3 secs should be enough. if not, increase it
  
  browser.get("http://ae.bizdirlib.com/taxonomy/term/1493") # Load page
  links = browser.find_elements_by_css_selector("h2 &gt; a")
  
  
  for link in links:
      link.send_keys(Keys.CONTROL + Keys.RETURN)
      link.send_keys(Keys.CONTROL + Keys.PAGE_UP)
      time.sleep(5)
      test()
      link.send_keys(Keys.CONTROL + 'w')
  
  
  
  def test(self):#test function
      elems = browser.find_elements_by_css_selector("div.content.clearfix &gt; div &gt; fieldset&gt; div &gt; ul &gt; li &gt; span")
  
      for elem in elems:
          print elem.text
      elem1 = browser.find_elements_by_css_selector("div.content.clearfix&gt;div&gt;fieldset&gt;div&gt;ul&gt;li&gt;a")
  
      for elems21 in elem1:
          print elems21.text 
      return 0
  </code></pre>
  
  <p>So I want to call the function and when the function is called I want the data to be copy/pasted into Excel.  </p>
  
  <p>Can somebody help me to enhance the code ?</p>