Downloading file with Python Selenium












0















I am trying to automate a workflow using python and selenium where i will open a page and download couple of .txt file.



My web driver initialization looks like below:



fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "c:\selenium_firefox_downloads\")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
driver = webdriver.Firefox(firefox_profile=fp)


The above code is working fine, but the problem is there are some files whose extension are in uppercase. For e.g. file.TXT, the above code is not working for this particular case.



Whenever i am trying to download files with .TXT extension instead of saving it to directory c:selenium_firefox_downloads firefox is giving me a popup window and asking me where to save it.



I am not sure if the MIME type 'text/plain' is compatible only .txt (i.e. in lowercase)



Could anyone please help me with this issue ?



Python version: 3.6.6 64bit on Windows 7
Selenium version: 3.141.0
Firefox version: 63.0.1 64bit
Gecko driver: 0.23.0










share|improve this question























  • you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

    – MEdwin
    Nov 13 '18 at 11:35













  • You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

    – Andersson
    Nov 13 '18 at 11:37













  • @Andersson Thanks for the suggestion, it helped.

    – Shirshendu Bhowmick
    Nov 13 '18 at 11:48
















0















I am trying to automate a workflow using python and selenium where i will open a page and download couple of .txt file.



My web driver initialization looks like below:



fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "c:\selenium_firefox_downloads\")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
driver = webdriver.Firefox(firefox_profile=fp)


The above code is working fine, but the problem is there are some files whose extension are in uppercase. For e.g. file.TXT, the above code is not working for this particular case.



Whenever i am trying to download files with .TXT extension instead of saving it to directory c:selenium_firefox_downloads firefox is giving me a popup window and asking me where to save it.



I am not sure if the MIME type 'text/plain' is compatible only .txt (i.e. in lowercase)



Could anyone please help me with this issue ?



Python version: 3.6.6 64bit on Windows 7
Selenium version: 3.141.0
Firefox version: 63.0.1 64bit
Gecko driver: 0.23.0










share|improve this question























  • you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

    – MEdwin
    Nov 13 '18 at 11:35













  • You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

    – Andersson
    Nov 13 '18 at 11:37













  • @Andersson Thanks for the suggestion, it helped.

    – Shirshendu Bhowmick
    Nov 13 '18 at 11:48














0












0








0








I am trying to automate a workflow using python and selenium where i will open a page and download couple of .txt file.



My web driver initialization looks like below:



fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "c:\selenium_firefox_downloads\")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
driver = webdriver.Firefox(firefox_profile=fp)


The above code is working fine, but the problem is there are some files whose extension are in uppercase. For e.g. file.TXT, the above code is not working for this particular case.



Whenever i am trying to download files with .TXT extension instead of saving it to directory c:selenium_firefox_downloads firefox is giving me a popup window and asking me where to save it.



I am not sure if the MIME type 'text/plain' is compatible only .txt (i.e. in lowercase)



Could anyone please help me with this issue ?



Python version: 3.6.6 64bit on Windows 7
Selenium version: 3.141.0
Firefox version: 63.0.1 64bit
Gecko driver: 0.23.0










share|improve this question














I am trying to automate a workflow using python and selenium where i will open a page and download couple of .txt file.



My web driver initialization looks like below:



fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "c:\selenium_firefox_downloads\")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
driver = webdriver.Firefox(firefox_profile=fp)


The above code is working fine, but the problem is there are some files whose extension are in uppercase. For e.g. file.TXT, the above code is not working for this particular case.



Whenever i am trying to download files with .TXT extension instead of saving it to directory c:selenium_firefox_downloads firefox is giving me a popup window and asking me where to save it.



I am not sure if the MIME type 'text/plain' is compatible only .txt (i.e. in lowercase)



Could anyone please help me with this issue ?



Python version: 3.6.6 64bit on Windows 7
Selenium version: 3.141.0
Firefox version: 63.0.1 64bit
Gecko driver: 0.23.0







python selenium web firefox automation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 11:30









Shirshendu BhowmickShirshendu Bhowmick

1137




1137













  • you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

    – MEdwin
    Nov 13 '18 at 11:35













  • You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

    – Andersson
    Nov 13 '18 at 11:37













  • @Andersson Thanks for the suggestion, it helped.

    – Shirshendu Bhowmick
    Nov 13 '18 at 11:48



















  • you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

    – MEdwin
    Nov 13 '18 at 11:35













  • You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

    – Andersson
    Nov 13 '18 at 11:37













  • @Andersson Thanks for the suggestion, it helped.

    – Shirshendu Bhowmick
    Nov 13 '18 at 11:48

















you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

– MEdwin
Nov 13 '18 at 11:35







you can expand the list to include : "application/txt,text/plain,text/txt,text/txt" . Problem solved.

– MEdwin
Nov 13 '18 at 11:35















You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

– Andersson
Nov 13 '18 at 11:37







You can open Dev tools (F12), switch to Network tab and check the exact MIME-type (content-type header) of target file

– Andersson
Nov 13 '18 at 11:37















@Andersson Thanks for the suggestion, it helped.

– Shirshendu Bhowmick
Nov 13 '18 at 11:48





@Andersson Thanks for the suggestion, it helped.

– Shirshendu Bhowmick
Nov 13 '18 at 11:48












1 Answer
1






active

oldest

votes


















0














As per the suggestion received from Andersson, i checked the MIME type of those and it seems to be different from text/plain. So i simply added the new MIME type to browser.helperApps.neverAsk.saveToDisk and it worked.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280086%2fdownloading-file-with-python-selenium%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As per the suggestion received from Andersson, i checked the MIME type of those and it seems to be different from text/plain. So i simply added the new MIME type to browser.helperApps.neverAsk.saveToDisk and it worked.






    share|improve this answer




























      0














      As per the suggestion received from Andersson, i checked the MIME type of those and it seems to be different from text/plain. So i simply added the new MIME type to browser.helperApps.neverAsk.saveToDisk and it worked.






      share|improve this answer


























        0












        0








        0







        As per the suggestion received from Andersson, i checked the MIME type of those and it seems to be different from text/plain. So i simply added the new MIME type to browser.helperApps.neverAsk.saveToDisk and it worked.






        share|improve this answer













        As per the suggestion received from Andersson, i checked the MIME type of those and it seems to be different from text/plain. So i simply added the new MIME type to browser.helperApps.neverAsk.saveToDisk and it worked.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 11:52









        Shirshendu BhowmickShirshendu Bhowmick

        1137




        1137






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280086%2fdownloading-file-with-python-selenium%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()