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_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)
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 import WebDriverWait
from import By
from import expected_conditions as EC

Browser Snapshot:

fixed deposit

Read more here: Source link