2016-07-29 116 views
2

我想使用硒按幾個按鈕爲我的測試過程下載文件。這個網頁使用Javascript,所以不可能像Http客戶端一樣使用像HttpState這樣的東西。我發現PhantomJs不支持這個功能(Linux上的Esspessialy)。我在Firefox中使用下面的代碼,但它不是無頭的。是否有任何支持硒的Downless瀏覽器支持下載功能

FirefoxProfile fprofile = new FirefoxProfile(); 
    String path; 
    if (SystemUtils.IS_OS_LINUX) { 
     path = "/tmp/hon/"; 
    } else { 
     path = "c:\\Downloads\\hon\\"; 
    } 
    fprofile.setPreference("browser.download.dir", path); 
    fprofile.setPreference("browser.download.folderList", 2); 
    fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");    fprofile.setPreference("browser.download.manager.showWhenStarting", false); 
    fprofile.setPreference("pdfjs.disabled", true); 
    mDriver = new FirefoxDriver(fprofile); 

是否有任何解決方案使用這樣的構造與一些無頭瀏覽器?

回答

0

您可以試試XVFB X11顯示服務器。它可以像真正的顯示器一樣在無頭模式下工作,可以拍攝截圖和其他東西。

+0

我無法使用這種方式,原因很多。至少我需要這個解決方案跨平臺。我正在尋找無頭瀏覽器,而不是顯示服務器。 –