Reputation: 697
I am new to selenium and below is my code to download pdf document of a daily newspaper using selenium from selenium import webdriver;
#Setting the profile
profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/pdf'))
profile.set_preference('browser.download.dir', '/home/jill/Downloads/Dinamalar');
browser = webdriver.Firefox();
browser.get("http://epaper.dinamalar.com/");
webobj = browser.find_element_by_id("liSavePdf");
ob = webobj.click();
The value of ob is None. I have checked many links and in all of them, there seems to be an explicit "download pdf" button which directly downloads the expected pdf. In my case, clicking "Save PDF" directs me to another page and from there one more "Download" button needs to be clicked.
I am not familiar with DOM objects. The "Save PDF" seems to be a DOM object. So I am not sure how to proceed further.
Upvotes: 1
Views: 997
Reputation: 6237
The element with id liSavePdf
is not the element which contains the onclick=
attribute. It contains a single a
element that you want to click:
webobj.find_elements_by_tag_name('a')[0].click()
Upvotes: 1
Reputation: 447
browser.execute_script('function downloadpdf(configPdfTypeValue){if(isLoginRequired){var response8=AjaxUtilsMethods.CheckUserLoginStatus();var strLogin=response8.value;if(strLogin=="InValid"){if(confirm("You need to Register Login to access this feature")){window.location.href=LoginPageURL;return false}else{return false}}}var current=currentslidepagenum;var fPath=$("#newslider").find("#"+currentslidepagenum+"").attr("src");var currPDFName;fPath=fPath.replace(".JPG","");fPath=fPath.replace(".jpg","");fPath=fPath.replace("Page","PagePrint");var PDFFileName=fPath.split("/");var PDFName="";PDFName=PDFFileName[PDFFileName.length-1];if(configPdfTypeValue=="1"){PDFName=PDFName.substring(0,10)}PDFName=PDFName+"_"+AjaxUtilsMethods.GetMD5ForGivenValue(PDFName+"_pressguess").value+".pdf";var path=fPath.substring(0,fPath.lastIndexOf("/")+1);PDFName=path+"/"+PDFName;return"http://epaper.dinamalar.com/"+PDFName}')
This will return the link of the PDF file
http://epaper.dinamalar.com/PUBLICATIONS/DM/MADHURAI/2015/05/26/PagePrint//26_05_2015_001_b2b69fda315301809dda359a6d3d9689.pdf
Upvotes: 1