Thursday 16 October 2014

Automatic File Download Selenium Java



Below code snippet for Firefox :-

Automatic File Download Selenium Java

---------------------------------------------------START-----------------------------------------------------

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import atu.utils.windows.handler.exceptions.WindowsHandlerException;


public class autoDownLoad {

public static void main(String[] args) throws WindowsHandlerException, InterruptedException {

 FirefoxProfile profile = new FirefoxProfile();
 String path="d:\\downloads123";
 profile.setPreference("browser.download.folderList", 2);
 profile.setPreference("browser.download.dir", path);
 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/csv,text/csv,image/png ,image/jpeg, application/pdf, text/html,text/plain,application/octet-stream");
 profile.setPreference("browser.download.manager.showWhenStarting", false);
 profile.setPreference("browser.download.manager.focusWhenStarting", false); 
 profile.setPreference("browser.download.useDownloadDir", true);
 profile.setPreference("browser.helperApps.alwaysAsk.force", false);
 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
 profile.setPreference("browser.download.manager.closeWhenDone", false);
 profile.setPreference("browser.download.manager.showAlertOnComplete", false);
 profile.setPreference("browser.download.manager.useWindow", false);
 profile.setPreference("browser.download.manager.showWhenStarting",false);
 profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
 profile.setPreference("pdfjs.disabled", true);
 WebDriver driver = new FirefoxDriver(profile);
driver.get(YOUR URL);
}

}


More Type--- > MIME TYPES

-----------------------------------------------------END------------------------------------------------------