python – How to download PDF by clicking using selenium chrome driver
To download the Domestic Fixed Deposits pdf from the website you need to click on the element inducing WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option('prefs', {
"download.default_directory": "C:\\Datafiles",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True
})
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://www.axisbank.com/interest-rate-on-deposits?cta=homepage-rhs-fd")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Domestic Fixed Deposits']//following-sibling::div[1]/span"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
Read more here: Source link