mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.17k stars 1.52k forks source link

File are not downloaded automatically #1533

Closed migmax48 closed 5 years ago

migmax48 commented 5 years ago

System

Testcase

GeckoDriver unforunatelly ask me to download file. My current profile settings are:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(true);
    profile.setPreference("browser.download.dir",  new File("./downloads").getAbsolutePath());
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, application/pdf, application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.manager.showWhenStarting", false);
    profile.setPreference("browser.helperApps.alwaysAsk.force", false);
    profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    profile.setPreference("browser.download.manager.focusWhenStarting", false);
    profile.setPreference("browser.download.manager.showWhenStarting", false);
    profile.setPreference("browser.download.manager.useWindow", false);
    profile.setPreference("browser.download.manager.showAlertOnComplete", false);
    profile.setPreference("browser.download.manager.closeWhenDone", false);
    profile.setPreference("browser.download.panel.shown", false);
    profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    profile.setPreference("browser.download.manager.focusWhenStarting", false);
    profile.setPreference("browser.download.manager.closeWhenDone", true);
    profile.setPreference("pdfjs.disabled", false);
    profile.setPreference("plugin.scan.plid.all", false);
    profile.setPreference("plugin.scan.Acrobat", "99.0");
    profile.setPreference("extensions.blocklist.enabled", false);
    profile.setPreference("media.gmp-manager.cert.requireBuiltIn",false);
    profile.setPreference("media.gmp-manager.cert.checkAttributes",false);
    profile.setPreference("media.gmp-provider.enabled",false);
    profile.setPreference("media.gmp-widevinecdm.enabled",false);
    profile.setPreference("media.gmp-widevinecdm.visible",false);
    profile.setPreference("media.gmp.trial-create.enabled",false);
    profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");

    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setJavascriptEnabled(true);
    capability.setCapability(FirefoxDriver.PROFILE, profile);

    System.setProperty("webdriver.gecko.driver",firefoxDriverPath);

    FirefoxOptions options = new FirefoxOptions();
    options.setProfile(profile);
    options.addArguments("--test-type", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors","--verbose","--disable-web-security");
    WebDriver driver = new FirefoxDriver(options);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

The dowload action is executed inside an iframe. What's wrong?

Trace-level log

console.error: BroadcastService: receivedBroadcastMessage: handler for remote-settings/monitor_changes threw error: Message: Error: Polling for changes failed: NetworkError when attempting to fetch resource.. Stack: remoteSettingsFunction/remoteSettings.pollChanges@resource://services-settings/remote-settings.js:190:13

whimboo commented 5 years ago

Download file for what? Nothing in your example code indicates that you trigger a navigation request. Also could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

migmax48 commented 5 years ago

Hi, the stream after calling document.Selezioni.submit () starts the download of a pdf file. The problem is that the "save as" window is shown and should not.

This is the code snippet that executes the action: driver.switchTo (). frame ( "ifrmGabbia2"); driver.findElement (By.xpath ( "// input [@ id = 'paramMatricola']")). SendKeys ( "XXXX"); ((JavascriptExecutor) driver) .executeScript ( "confermaRicercaMatricola ();"); driver.findElement (By.xpath ("// a [@ title = 'View Print']")). click (); driver.findElement (By.xpath ( "// input [@ name = 'selectAll']")). click (); driver.manage (). timeouts (). setScriptTimeout (120, TimeUnit.SECONDS); try { Thread.sleep (10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace (); } ((JavascriptExecutor) driver) .executeScript ( "document.Selezioni.submit ();"); try { Thread.sleep (20000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace (); }

This is the requested trace log:

1553690513534 webdriver :: server DEBUG <- 200 OK {"value": null} 1553690513538 webdriver :: server DEBUG -> POST / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / element {"value": "// input [@name u003d u0027selectAll u0027]", "using": "xpath "} 1553690513539 Marionette DEBUG 0 -> [0.59, "WebDriver: FindElement", {"using": "xpath", "value": "// input [@ name = 'selectAll']"}] 1553690513545 Marionette DEBUG 0 <- [1,59, null, {"value": {"element-6066-11e4-a52e-4f735466cecf": "b20180aa-e8fe-1d44-964c-bc24d8e8e066"}}] 1553690513546 webdriver :: server DEBUG <- 200 OK {"value": {"element-6066-11e4-a52e-4f735466cecf": "b20180aa-e8fe-1d44-964c-bc24d8e8e066"}} 1553690513550 webdriver :: server DEBUG -> POST / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / element / b20180aa-e8fe-1d44-964c-bc24d8e8e066 / click {"id": "b20180aa-e8fe-1d44-964c-bc24d8e8e066 "} 1553690513551 Marionette DEBUG 0 -> [0.60, "WebDriver: ElementClick", {"id": "b20180aa-e8fe-1d44-964c-bc24d8e8e066"}] 1553690513763 DEBUG puppets [4294967297] Canceled page load listener because no navigation has been detected 1553690513764 Marionettes DEBUG 0 <- [1.60, null, {"value": null}] 1553690513765 webdriver :: server DEBUG <- 200 OK {"value": null} 1553690513768 webdriver :: server DEBUG -> POST / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / timeouts {"script": 120000} 1553690513770 Marionette DEBUG 0 -> [0.61, "WebDriver: SetTimeouts", {"script": 120000}] 1553690513770 Marionettes DEBUG 0 <- [1.61, null, {"value": null}] 1553690513771 webdriver :: server DEBUG <- 200 OK {"value": null} 1553690523778 webdriver :: server DEBUG -> POST / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / execute / sync {"script": "document.Selezioni.submit ();", "args": []} 1553690523780 Marionette DEBUG 0 -> [0.62, "WebDriver: ExecuteScript", {"args": [], "script": "document.Selezioni.submit ();"}] 1553690523787 Marionette DEBUG 0 <- [1.62, null, {"value": null}] 1553690523788 webdriver :: server DEBUG <- 200 OK {"value": null} 1553690543796 webdriver :: server DEBUG -> POST / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / elements {"value": "// a [@id u003d u0027card-user-menu u0027]", "using "" xpath "} 1553690543798 Marionette DEBUG 0 -> [0.63, "WebDriver: FindElements", {"using": "xpath", "value": "// a [@ id = 'card-menu-user']"}] 1553690553803 Marionettes DEBUG 0 <- [1.63, null, []] 1553690553804 webdriver :: server DEBUG <- 200 OK {"value": []} 1553690553807 webdriver :: server DEBUG -> DELETE / session / 8b56468c-e590-1243-b21a-1f66b4af95ce / window 1553690553809 Marionette DEBUG 0 -> [0.64, "WebDriver: CloseWindow", {}] 1553690553824 Marionette TRACE Received DOM event unload for [object XULDocument] 1553690553834 Marionette TRACE Received observer notification message-manager-disconnect 1553690553836 Marionette DEBUG 0 <- [1.64, null, []] 1553690553845 webdriver :: server DEBUG Last window was closed, deleting session 1553690553845 webdriver :: server DEBUG Deleting session 1553690553882 Marionette DEBUG 0 -> [0.65, "Marionette: Quit", {"flags": ["eForceQuit"]}] 1553690553883 Marionette INFO Stopped listening on port 65354 1553690553908 addons.xpi DEBUG Calling bootstrap method shutdown on webcompat@mozilla.org version 3.0.2 1553690553912 addons.xpi DEBUG Calling bootstrap method shutdown on screenshots@mozilla.org version 35.0.0 1553690553915 addons.xpi DEBUG Calling bootstrap method shutdown on formautofill@mozilla.org version 1.0 1553690553925 Marionette TRACE Received observer notification quit-application 1553690553929 Marionette DEBUG 0 <- [1,65, null, {"cause": "shutdown"}] 1553690553948 Marionette DEBUG Closed connection 0 1553690553964 addons.manager DEBUG shutdown 1553690553967 addons.manager DEBUG Calling shutdown blocker for XPIProvider 1553690553967 addons.xpi DEBUG shutdown 1553690553967 addons.xpi-utils DEBUG shutdown 1553690553967 addons.manager DEBUG Calling shutdown blocker for LightweightThemeManager 1553690553967 addons.manager DEBUG Calling shutdown blocker for GMPProvider 1553690553967 addons.manager DEBUG Calling shutdown blocker for PluginProvider 1553690553971 addons.manager DEBUG Async provid

whimboo commented 5 years ago

I would suggest that you check the MIME type of the PDF file as served by that host. I could imagine that it is not the one which you set in your preferences. As such it won't be handled. Note that this isn't a bug/problem with geckodriver.

Please let us know anyway if you were able to solve it.

migmax48 commented 5 years ago
Schermata 2019-03-28 alle 22 27 38

Unfortunately the mimetype is correct :-(

whimboo commented 5 years ago

No, this is the MIME type from your local host, but not from the remote server.

batouxclass commented 5 years ago

The same issue:

1555093608442 geckodriver INFO Listening on 127.0.0.1:45442 1555093609147 mozprofile::profile INFO Using profile path C:\Users\xxxxx\AppData\Local\Temp\rust_mozprofile.Ehkbgpc9GRED 1555093609165 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe 1555093609175 geckodriver::marionette INFO Connecting to Marionette on localhost:50028 1555093609589 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons 1555093609590 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ 1555093609590 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* 1555093610875 Marionette INFO Listening on port 2828 console.error: BroadcastService: receivedBroadcastMessage: handler for remote-settings/monitor_changes threw error: Message: Error: Polling for changes failed: NetworkError when attempting to fetch resource.. Stack: remoteSettingsFunction/remoteSettings.pollChanges@resource://services-settings/remote-settings.js:190:13

lock[bot] commented 5 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.