Download file from sharepoint using selenium webdriver python -
i trying download file sharepoint url , written code neverask.savetodisk
still showing dialog save file. tried same code , works when click download link other url not working sharepoint application. here code used...
from selenium import webdriver selenium.webdriver.firefox.firefox_profile import firefoxprofile # prevent download dialog profile = webdriver.firefoxprofile() profile.set_preference('browser.download.folderlist', 2) # custom location profile.set_preference('browser.download.manager.showwhenstarting', false) profile.set_preference("browser.download.defaultfolder",'tt_at'); profile.set_preference("browser.download.lastdir",'tt_at'); profile.set_preference('browser.download.dir', 'tt_at') profile.set_preference("browser.download.usedownloaddir",true); profile.set_preference('browser.helperapps.neverask.savetodisk', "application/octet-stream,application/msexcel") browser = webdriver.firefox(profile) browser.get("https://docs.ad.sys.com/sites/cloud/project/form/folderctid=0x01200069047c40c93c3846b74e0776aad1610a&initialtabid=ribbon%2edocument&visibilitycontext=wsstabpersistence") browser.find_element_by_xpath('/html/body/form/div[8]/div/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/table/tbody/tr/td/div/table[1]/tbody/tr/td/table/tbody/tr[12]/td[4]/div[1]/a').click()
but above code still showing dialog select location.
i think got solution, try following:
from selenium import webdriver selenium.webdriver.firefox.firefox_profile import firefoxprofile profile = webdriver.firefoxprofile() #give complete path of download dir profile.set_preference("browser.download.lastdir",r'd:\temp') profile.set_preference("browser.download.usedownloaddir",true) profile.set_preference("browser.download.manager.showwhenstarting",false) profile.set_preference('browser.helperapps.neverask.savetodisk',"application/vnd.ms-excel,content-type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream") profile.set_preference('browser.helperapps.neverask.openfile', "application/vnd.ms-excel,content-type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream") browser = webdriver.firefox(profile) browser.get("https://docs.ad.sys.com/sites/cloud/project/form/folderctid=0x01200069047c40c93c3846b74e0776aad1610a&initialtabid=ribbon%2edocument&visibilitycontext=wsstabpersistence") browser.find_element_by_xpath('/html/body/form/div[8]/div/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/table/tbody/tr/td/div/table[1]/tbody/tr/td/table/tbody/tr[12]/td[4]/div[1]/a').click()
if not working you, following, install addon tamperdata in firefox , observe content type file trying download , add exact text "browser.helperapps.neverask.*" preference. shall solve problem!