florentbr / SeleniumBasic

A Selenium based browser automation framework for VB.Net, VBA and VBScript
BSD 3-Clause "New" or "Revised" License
433 stars 198 forks source link

Selenium - VBA problem while downloading the file automatically using FIREFOX #131

Open githubbyguru opened 8 years ago

githubbyguru commented 8 years ago

Hi I am Guruprasad working on Selenium - VBA to automate a download of a xls report using Firefox.

I tried to setPreference but still it is asking my Firefox open file dialog while saving the file following are my details:

Firefox version: 46.0 I am using the Firefox web driver through Excel sheet

Following is my code:

Public Sub testing_selenium_FireFox_driver()

Dim objs As New FirefoxDriver

On Error GoTo error_Firefox_driver

Dim strpath As String strpath = "C:\"

objs.setPreference "browser.download.folderList", 2 objs.setPreference "browser.download.dir", path objs.setPreference "browser.download.manager.alertOnEXEOpen", False objs.setPreference "browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel, application/x-download, application/msword, application/msexcel, application/xls, 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" objs.setPreference "browser.download.manager.showWhenStarting", False objs.setPreference "browser.download.manager.focusWhenStarting", False objs.setPreference "browser.download.useDownloadDir", True objs.setPreference "browser.helperApps.alwaysAsk.force", False objs.setPreference "browser.download.manager.alertOnEXEOpen", False objs.setPreference "browser.download.manager.closeWhenDone", True objs.setPreference "browser.download.manager.showAlertOnComplete", False objs.setPreference "browser.download.manager.useWindow", False objs.setPreference "services.sync.prefs.sync.browser.download.manager.showWhenStarting", False objs.setPreference "pdfjs.disabled", True

objs.Get "" objs.Window.Maximize

Please let me know what I am doing wrong here.. It is surely not working as when I am testing the file is not geting automatically saved on the provided location.

Please somebody can help urgently that will be a great help this is the only step remaining from myside to complete.

mogulman52 commented 8 years ago

I got it to work by adding 1 line. When the prompt comes up the first time click Save and click the checkbox to do this for docs of this type. You won't get the prompt on subsequent saves. The line I added was to make the profile persistent. That way it remembers what you set rather than creating a new profile in a temp dir.

`Public Sub testing_selenium_FireFox_driver()

Dim objs As New FirefoxDriver objs.SetProfile "Download", persistant:=True ' Added

objs.setPreference "browser.download.folderList", 2 objs.setPreference "browser.download.dir", "C:\temp" objs.setPreference "browser.download.manager.alertOnEXEOpen", False objs.setPreference "browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel, application/x-download, application/msword, application/msexcel, application/xls, 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" objs.setPreference "browser.download.manager.showWhenStarting", False objs.setPreference "browser.download.manager.focusWhenStarting", False objs.setPreference "browser.download.useDownloadDir", True objs.setPreference "browser.helperApps.alwaysAsk.force", False objs.setPreference "browser.download.manager.alertOnEXEOpen", False objs.setPreference "browser.download.manager.closeWhenDone", True objs.setPreference "browser.download.manager.showAlertOnComplete", False objs.setPreference "browser.download.manager.useWindow", False objs.setPreference "services.sync.prefs.sync.browser.download.manager.showWhenStarting", False objs.setPreference "pdfjs.disabled", True

objs.Get "http://..../mydoc.docx" objs.Window.Maximize End Sub`