简体   繁体   中英

Upload recent downloaded file using Selenium webdriver- PYTHON

I want to upload a file using Selenium whose name I don't know, the only thing I know is that it's in the downloads folder and it's the recent file. How can I do so?

It has nothing to do with selenium. You can use native libraries from python to obtain desired result.

import os
import glob

# * matches all files in directory
# if you need other specific file types
# use *.[type], for example *.py
files_in_dir = glob.glob('[path to your folder]/*') 
recent_file = max(list_of_files, key=os.path.getctime)

os.path.getctime refers to last metadata change time in current path in system. This way you can filter out and get most recent file with recent date.
glob module is used to find specific file patterns in specified directory. Read more about glob here .
os module provides some utility capabilites from operating system. More about os here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM