0

I am using selenium web driver and downloading .pdf files from internet using firefox, but i could not able to save these files on local machine using relative path ( i am using windows 7 32 bit machine ). It is working fine if i am using absolute path. But i only want to use relative path as i also need to run it on server later. My Code:

public static void main(String args[]) throws ClassNotFoundException, IOException{

    FirefoxProfile fprofile = new FirefoxProfile();
    fprofile.setPreference("browser.download.useDownloadDir", true);
    fprofile.setPreference("browser.download.dir", "./Folder");
    fprofile.setPreference("browser.download.folderList", 2);
    fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf;");
    fprofile.setPreference( "browser.download.manager.showWhenStarting", false );
    fprofile.setPreference( "pdfjs.disabled", true );
    fprofile.setPreference("plugin.scan.plid.all", false);
    fprofile.setPreference("plugin.scan.Acrobat", "99.0");

    WebDriver driver = new FirefoxDriver(fprofile);
djangofan
  • 28,471
  • 61
  • 196
  • 289
  • For Java, there is a project called Selenide that has pre-built operations in it for handling downloads. – djangofan Dec 10 '15 at 16:59

1 Answers1

0

I did something like this in my ruby code

download_directory = File.join(File.absolute_path('../..', File.dirname(__FILE__)),"downloads")

I believe that it will be similiar in java - get absolute path from relative path

Path path = FileSystems.getDefault().getPath("./Folder");
String absolutePath = path.toAbsolutePath().toString();

http://www.javacodex.com/Files/Converting-A-Relative-Path-Into-An-Absolute-Path

Kit Fung
  • 481
  • 3
  • 10