为了避免将路径名硬编码到我的下载文件夹,我使用XML文件来存储我的路径名。
以下是代码:
public class Driver
{
//public static WebDriver driver=new FirefoxDriver(FFprofile());
public static WebDriver driver=new FirefoxDriver(FFprofile(downloadPath));
// Method to handle firefox browser profile
//public static FirefoxProfile FFprofile()
public static FirefoxProfile FFprofile(String downloadPath)
{
FirefoxProfile profile = new FirefoxProfile();
//String downloadPath="C:\\Users\\XXXX\\Downloads";
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", downloadPath);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel,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.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);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("pdfjs.disabled", true);
return profile;
}
}
现在的问题是行中有错误:
public static WebDriver driver=new FirefoxDriver(FFprofile(downloadPath));
错误是:
downloadPath cannot be resolved to a variable.
我的XML文件的快照:
<parameter name="downloadPath" value="C:\\Users\\XXXXX\\Downloads"/>
请指导我如何处理错误?