I am trying to get the current url of an item which is already in a loop
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
but i got the first actual link but the code stopped,
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)
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.