Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir-Webdriver Wait for Download to Complete

I am using Watir-Webdriver with Firefox and the method recommended on the watirwebdriver.com site to automate file downloads. This involves setting FireFox about:config parameters to disable the download dialog in FireFox for specific file types. This works well but now I am trying to figure out how best to determine when the file download has completed (some take a few seconds, some take minutes) so I can logout of the site and move on to the next test. It seems since there are no visual clues left in the browser I may have to monitor the file in the download directory. Any options would be appreciated.

like image 930
user1142012 Avatar asked Jan 11 '12 00:01

user1142012


People also ask

How wait till download is complete in selenium?

There is no built-in to selenium way to wait for the download to be completed. The general idea here would be to wait until a file would appear in your "Downloads" directory. Hope this helps!!

Does Watir use selenium?

Watir is an open-source web application testing framework that is designed to make writing Selenium tests simple and efficient. Built on Selenium's Ruby language bindings, Watir is able to drive the browser in the same way humans do.

How do you check if a file is downloaded in selenium Python?

Once the download is completed, we can verify it with the help of the os. path. isfile method. The path of the downloaded file is passed as a parameter to that method.


1 Answers

I had a similar task where I wanted to extract the contents of a downloaded PDF file. I used to following solution:

t = ''
(0..19).each do
  sleep 5
  t = `pdftotext -raw some_directory/*.pdf -`
  break if $?.success?
end

It does 20 attempts at extracting the text using the shell command pdftotext and will break out of the block if the shell command was successful. The advantage of doing it this way is that if the file doesn't exist or if the file is only partially downloaded it will produce an error and then try again. If your file is not a PDF or you don't care about the contents then you use another shell command instead of pdftotext, so long as it produces an error if the file is incomplete.

like image 86
Dave Sexton Avatar answered Oct 11 '22 02:10

Dave Sexton