Firefox download

阅读更多
  FirefoxProfile firefoxProfile = new FirefoxProfile();

firefoxProfile.setPreference("browser.download.folderList",2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
    firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");

    WebDriver driver = new FirefoxDriver(firefoxProfile);




------------------------------------------------------------------------
driver.findElement(By.linkText("Instant Selenium Testing Tools
Starter")).click();
   add below code it ll work
Robot robo=new Robot();
  robo.keyPress(KeyEvent.VK_ENTER);

----------------------------------------------------------------------

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
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", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
/* you will need to find the content-type of your app and set it here. */
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
profile.setPreference("browser.download.dir",path);

String file_types = "application/acrobat, application/nappdf, application/x-pdf, application/vnd.pdf, text/pdf, text/x-pdf, " +
"text/comma-separated-values,text/csv,application/pdf, application/x-msdos-program, application/x-unknown-application-octet-stream,"
             + "application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel,"
             + "application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip, application/x-stuffit,"
             +"application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar,"
             + "video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff, text/plain, application/vnd.ms-excel [official],"
             + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msexcel, application/x-msexcel,"
             + "application/x-excel, application/vnd.ms-excel, application/excel, application/x-ms-excel, application/x-dos_ms_excel,"
             + "text/csv, text/comma-separated-values, application/octet-stream, application/haansoftxls, application/msexcell,"
             + "application/softgrid-xls, application/vnd.ms-excel, x-softmaker-pm";

profile.setPreference("browser.helperApps.neverAsk.saveToDisk", file_types);

File fin = new File(path);
  if (!fin.exists()) {   
  fin.mkdirs();   
          }  

File pathToBinary = new File("C:/Program Files (x86)/FrontMotion/Firefox/firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
ESGManagerFireFoxWebDriver esgManagerFireFoxWebDriver = new ESGManagerFireFoxWebDriver(ffBinary,profile);
esgManagerFireFoxWebDriver.manage().window().setPosition(new Point(0,0));
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
    esgManagerFireFoxWebDriver.manage().window().setSize(dim);
return esgManagerFireFoxWebDriver;

你可能感兴趣的:(Firefox download)