如何在Ruby Selenium WebDriver中使用相对路径使用Firefox下载文件?
我正在使用selenium web驱动程序并使用firefox从internet下载.pdf文件,但我无法使用相对路径将这些文件保存在本地计算机上(我正在使用windows 7 32位计算机)。如果我使用绝对路径,它可以正常工作。但我只想使用相对路径,因为我以后还需要在服务器上运行它。 我的代码:如何在Ruby Selenium WebDriver中使用相对路径使用Firefox下载文件?,firefox,selenium,selenium-webdriver,selenium-ruby,Firefox,Selenium,Selenium Webdriver,Selenium Ruby,我正在使用selenium web驱动程序并使用firefox从internet下载.pdf文件,但我无法使用相对路径将这些文件保存在本地计算机上(我正在使用windows 7 32位计算机)。如果我使用绝对路径,它可以正常工作。但我只想使用相对路径,因为我以后还需要在服务器上运行它。 我的代码: public static void main(String args[]) throws ClassNotFoundException, IOException{ FirefoxProfi
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);
我在ruby代码中做了类似的事情
download_directory = File.join(File.absolute_path('../..', File.dirname(__FILE__)),"downloads")
我相信在java中也会类似——从相对路径中获取绝对路径
Path path = FileSystems.getDefault().getPath("./Folder");
String absolutePath = path.toAbsolutePath().toString();
对于Java,有一个名为Selenide的项目,其中包含用于处理下载的预构建操作。