The ChromeDriver for Selenium was able to open an embedded PDF after login, but how can I save the PDF file in chrome to local disk? thanks.
-
3Welcome to Stackoverflow! You're likely to get a better response to your question if you post some code that shows what you've tried to solve the problem yourself.NoChinDeluxe– NoChinDeluxe2015-10-28 22:21:36 +00:00Commented Oct 28, 2015 at 22:21
-
I managed to achieve the task by disable chrome pdf viewer and let the chrome browser directly download the pdf filejli– jli2015-10-30 14:09:15 +00:00Commented Oct 30, 2015 at 14:09
-
Possible duplicate of Chromedriver, Selenium - Automate downloadsNemo– Nemo2018-05-07 09:52:17 +00:00Commented May 7, 2018 at 9:52
Add a comment
|
1 Answer
def download_pdf(lnk):
options = webdriver.ChromeOptions()
tgt = tempfile.mkdtemp()
profile = {"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}],
"download.default_directory" : tgt}
options.add_experimental_option("prefs",profile)
driver = webdriver.Chrome(CHROMEDRIVER, chrome_options = options)
driver.get(lnk)
driver.find_element_by_id('userName1').send_keys('username')
driver.find_element_by_id('password1').send_keys('password')
driver.find_element_by_id('loginButton1').click()
ftgt = os.path.join(tgt,'downloaed.pdf')
while not os.path.exists(ftgt):
time.sleep(3)
driver.close()
return ftgt
1 Comment
B Furtado
Why is it necessary to use tempfile? And why to wait for os.path.exists?