title: How to Get the Current URL of an Item in a Loop Using Selenium
body: <p>I am trying to get the current url of an item which is already in a loop</p>
  
  <pre><code>def get_financial_info(self):
      chrome_options = Options()
      chrome_options.add_argument("--headless")
      chrome_options.add_argument("--window-size=1920x1080")
      driver = webdriver.Chrome(executable_path='/path/chromedriver')
  
      driver.get("https://www.financialjuice.com")
  
      try:
          WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='trendWrap']")))
      except TimeoutException:
          driver.quit()
  
      category_url = [a.get_attribute("href") for a in
                      driver.find_elements_by_xpath("//ul[@class='nav navbar-nav']/li[@class='text-uppercase']/a[@href]")]
  
      for record in category_url:
          driver.get(record)
          item = {}
          url_element = webdriver.find_elements_by_xpath("//p[@class='headline-title']/a[@href]")
  
          for links in url_element:
              driver.get(links.get_attribute("href"))
              print driver.current_url
  </code></pre>
  
  <p>but i got the first actual link but the code stopped,</p>
  
  <p><a href="http://www.zerohedge.com/news/2017-08-26/brief-history-tail-risk-ltcm-abx-cds-vix?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+zerohedge%2Ffeed+%28zero+hedge+-+on+a+long+enough+timeline%2C+the+survival+rate+for+everyone+drops+to+zero%29" rel="nofollow noreferrer">http://www.zerohedge.com/news/2017-08-26/brief-history-tail-risk-ltcm-abx-cds-vix?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+zerohedge%2Ffeed+%28zero+hedge+-+on+a+long+enough+timeline%2C+the+survival+rate+for+everyone+drops+to+zero%29</a></p>
  
  <pre><code>selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
    (Session info: headless chrome=62.0.3202.94)
    (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.4.0-101-generic x86_64)
  </code></pre>
  
  <p>i tried studying what happened, i realized that, the webdriver opened the first category, choose the first item and got the actual link and it stopped instead of going back to the previous url, take the second item and get the next link, till the loop ends.</p>