How to use Selenium and Firefox version 40, how to download a file?

Old file upload methods through Selenium no longer work.

My code is:

    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.download.dir", os.getcwd())
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
                      "application/pdf")

    self.driver = webdriver.Firefox(firefox_profile=fp)
    self.longMessage = True

However, the file dialog is still displayed. I turned many fields on and off, but after a little digging, I found that there was no difference between the prefs.jsdefault Firefox profile file generated by Selenium and the file prefs.jswhere I manually checked "Do this automatically for files of this type from now on" in the download dialog .

The file is mimeTypes.rdfmodified, although, in particular, the following lines are added:

<RDF:Description RDF:about="urn:mimetype:handler:application/pdf"
               NC:alwaysAsk="false"
               NC:saveToDisk="true"
               NC:handleInternal="false">
<NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/pdf"/>

I do not know how to configure my own mimeTypes.rdf file when creating a new Firefox profile. Somebody knows?

-, , URL- , , , .pdf .

+4
2

R, R, RSelenium. python, , .

known_formats <- c("application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")


firefox_profile.me <- makeFirefoxProfile(list(marionette = TRUE,
                                              # this is for certificate issues [may be ignored]
                                              webdriver_accept_untrusted_certs = TRUE,
                                              webdriver_assume_untrusted_issuer = TRUE,
                                              # download related settings
                                              browser.download.folderList = 2L,
                                              browser.download.manager.showWhenStarting = FALSE,
                                              # put your path here but remember to give path like C:\\DirOfYourChoice and not C:\\DirOfYourChoice\\ [last \\ is not going to work]
                                              browser.download.dir = normalizePath("TestDL"),
                                              browser.helperApps.alwaysAsk.force = FALSE,
                                              browser.helperApps.neverAsk.openFile = paste0(known_formats, collapse = ","),
                                              browser.helperApps.neverAsk.saveToDisk = paste0(known_formats, collapse = ","),
                                              browser.download.manager.showWhenStarting = FALSE,
                                              # this is for marionette and related security
                                              "browser.tabs.remote.force-enable" = TRUE,
                                              pdfjs.disabled = TRUE))

remDr <- remoteDriver(remoteServerAddr = "localhost",
                      port = 4444,
                      browserName = "firefox",
                      extraCapabilities = firefox_profile.me)

remDr$open()

remDr$navigate("https://www.google.com/search?q=sample+xlsx")

remDr$findElement(using = "css selector", value = ".g:nth-child(1) a")$clickElement()

remDr$navigate("https://www.google.com/search?q=test+xls")

remDr$findElement(using = "css selector", value = ".g:nth-child(1) a")$clickElement()

Firefox 50.1.0 [while I'm writing this post]
Selenium [3.0.1]
R [3.3.2 (2016-10-31)]

, python. firefox makeFirefoxProfile

: -
Selenium
Firefox Selenium

+2

.

frommy # code:

public Bitmap Image
        {
            get
            {
                string webPath = Element.GetAttribute("src");

                if (webPath != string.Empty)
                {
                    try
                    {
                        System.Net.WebRequest request =
                            System.Net.WebRequest.Create(webPath);

                        System.Net.WebResponse response = request.GetResponse();

                        System.IO.Stream responseStream = response.GetResponseStream();

                        Bitmap bitmapImg = new Bitmap(responseStream);

                        return bitmapImg;
                    }
                    catch (System.Net.WebException)
                    {
                    }
                }

                return new Bitmap(1,1);
            }
        }

, src , ( HDD). =)

-1

All Articles