Chirag verma
Chirag verma

Reputation: 343

Unable to download a CSV file using Selenium Python

I am unable to download a CSV file using Selenium Python. The download dialog keep popping up and the file does not get downloaded.

The following is the dialog box I get upon downloading

Dialog Box on downloading

from selenium import webdriver
from BasePage import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.keys import Keys
import unittest
from selenium.webdriver.support.select  import Select
import time
from selenium.webdriver.support.ui      import WebDriverWait
import os
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())

fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "test/csv")

# fp.set_preference("pdfjs.disabled", True)

browser = webdriver.Firefox(firefox_profile=fp)

Upvotes: 0

Views: 1469

Answers (1)

alecxe
alecxe

Reputation: 473833

It's not test/csv, it should be text/csv instead.

If this is not working, the file might have a different mime type, try the following:

fp.set_preference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream")

Upvotes: 0

Related Questions