**from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
chrome_path = r"C:/chromedriver.exe"
chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\\Users\\adarshb061\\Desktop",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}]}
chrome_profile.add_experimental_option("prefs", profile)
chrome_profile.add_argument("--disable-extensions")
browser = webdriver.Chrome(chrome_options=chrome_profile, executable_path=chrome_path)
browser.get("https://rbi.org.in/")
browser.maximize_window()
browser.find_element_by_xpath("""//*[@id="FEMA"]/a""").click()
browser.find_element_by_xpath("""//*[@id="FEMANotifications"]""").click()
def download_lnk(url):
browser.get(url)
browser.execute_script("window.history.go(-1)")
rows = browser.find_elements_by_xpath("//table[@class='tablebg']//tr//td/a[contains(@href,'http://')]")
for row in rows:
pdf_link = row.get_attribute('href')
print(pdf_link)
download_lnk(pdf_link)**
It is downloading only one PDF file from the web table. After that is giving me below exception: selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
Please suggest? Thanks in advance!