简体   繁体   中英

file download dialog in firefox

iam working on selenium+python programming by using firefox, automatically start the download and save file.i have done every thing but unable to download the csv file. my python version is 2.6.6 and my selenium version is latest version. i tried by using the following link also(ie)

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
browser = webdriver.Firefox(firefox_profile=fp)

i used this but i dint get the file and iam not geting any error also. any one plz help me..

my file is ![i got till here and my next step is to download it by using selenium+python program][1]

if any one have the solution plz help me.

Here is a complete example that works for me using Firefox 3.6.24 and 8.0.1.

#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.dir',"/tmp/webdriver-downloads")
profile.set_preference('browser.download.folderList',2)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv")
driver = webdriver.Firefox(profile)
base_url = "http://localhost/"
driver.get(base_url + "/text.csv")

Are you certain that your web server is returning text/csv as the Mime Type? One way to verify is using curl to confirm the Content-Type header in the HTTP response is what you expect:

$ curl -v http://localhost/text.csv
* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... connected
> GET /text.csv HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-apple-darwin10.8.0) libcurl/7.23.1 OpenSSL/1.0.0e zlib/1.2.5 libidn/1.22
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 28 Dec 2011 17:10:46 GMT
< Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8r DAV/2
< Last-Modified: Wed, 28 Dec 2011 17:05:47 GMT
< ETag: "291f98-0-4b52a02cbb0c0"
< Accept-Ranges: bytes
< Content-Length: 0
< Cache-Control: max-age=300
< Expires: Wed, 28 Dec 2011 17:15:46 GMT
< Content-Type: text/csv
< 
* Connection #0 to host localhost left intact
* Closing connection #0

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