Is it possible to find out which file is loaded by Firefox using Selenium

first of all, sorry for my english

I am doing some Python scripts using Selenium RC. The goal is to access some website and upload some files. I would like to know, at the end of the script, which files were downloaded exactly

At that moment I am doing something a little naive, checking for new files that appear in the Firefox download directory, it works well, but if I launched several clients at the same time, they won’t be able to find which files they belong to, etc. d.

So, I tried to find a solution to this problem, if it was possible to process the download from Firefox, to know exactly when the download occurs and what was downloaded, then I would be fine, but so far I don’t know anything about it

thanks for the help

+3
source share
4 answers

If you are working with python -> Selenium RC, why don’t you just create the lastdownload.txt file and enter the dates, file names of the uploaded files.

So, every time the script is run, it checks the file server and the log file to see which files are new, which files you already have. (if you use the same file name you can check the lastupdatetime headers or even the file size as a comparison method)

Then you just upload the new files ... so that you replicate the simple incremental mechanism by searching in the txt file ...

0
source

, -, ( Firefox), ( moz_downloads API Firefox)

def check_download(self):
    isDownloading = False
    t = 0
    while t != 60 or isDownloading:
        shutil.copy(os.path.join(self.finalFolder, "downloads.sqlite"), os.path.join(self.log_dir, self.sessionId+"downloads.sqlite"))
        conn = sqlite3.connect(os.path.join(self.log_dir, self.sessionId+"downloads.sqlite"))
        c = conn.cursor()
        c.execute("select state, target from moz_downloads")
        print '<waiting for download>'
        for row in c:
            dlState = row[0]
            dlTarget = row[1]
            if dlState == 0 or dlState == 7 or dlState == -1:
                isDownloading = True
            if self.verbose:
                print "status: {0} | target: {1}".format(dlState, dlTarget)
            if dlState == 1:
                filenameExpected = os.path.join(self.download_dir, os.path.split(dlTarget)[1])
                self.writeline_log("FILE;" + filenameExpected + ';')
                return
        c.close()
        conn.close()
        time.sleep(1)
        t = t + 1
0

, , Firefox, , (, , , Selenium2 - , ). , .

0

. , , (Ex: folder1, folder2, Folder3.....)

0

Source: https://habr.com/ru/post/1772876/


All Articles