How to change default download folder while webdriver is running?

后端 未结 1 2016
时光说笑
时光说笑 2020-12-18 09:36

I am downloading several different data sets and would like each file (or set) to download to a specific folder. I have learned how to change the download directories at the

相关标签:
1条回答
  • 2020-12-18 10:19

    In the past, I have solved this by downloading to a temp folder and then renaming the file to the appropriate folder with something along the line of this:

    def move_to_download_folder(downloadPath, newFileName, fileExtension):
        got_file = False   
        ## Grab current file name.
        while got_file = False:
            try: 
                currentFile = glob.glob(DOWNLOAD_PATH+"*"+fileExtension)
                got_file = True
    
            except:
                print "File has not finished downloading"
                time.sleep(20)
    
        ## Create new file name
        fileDestination = downloadPath+newFileName+fileExtension
    
        os.rename(currentFile, fileDestination)
    
        return
    
    ## Click element to download file
    inputElement=driver.find_element_by_xpath("{xpath here}").click()
    
    move_to_download_folder(downloadPath, newFileName, fileExtension)
    
    0 讨论(0)
提交回复
热议问题