
I need to save the web page on local driver, i.e. a html file with all it's asset, by programmatically (in Java on Windows) setting the director/fileName and save the page without manual input. I can't use the dirver.getPageSourse(), since it doesn't download the related page asset like CSS and js files.
I tried the Firefox profile, but it doesn't work( is it because it's only for forcing auto save when clicking a link, instead of "save as" dialog?). Here is what I tried:
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList", 2);
fxProfile.setPreference("browser.download.manager.showWhenStarting",
false);
fxProfile.setPreference("browser.download.dir", "c:\\temp");
fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"text/html; charset=UTF-8");
WebDriver driver = new FirefoxDriver(fxProfile);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// And now use this to visit Google
driver.get("http://www.whateverpage.com");
WebElement ele = driver.findElement(By
.xpath("An Valide Xpath pointing any valid element on the page"));
//simulate Ctl+S for "save as"
ele.sendKeys(Keys.CONTROL + "s");It only displays "Save As" dialog with the path pointing to the directory I specified in FirefoxProfile (i.e. C:\\temp), but I have no idea how to access\interact with this dialog, so I can specify the fileName and make it save automatically.
I haven't tried the AutoIt yet, but my questions are:
1. The "Save as" dialog is an OS dialog, not a browser one?
2. The FireFox profile failed, is it because it's only for forcing auto save when clicking a link, instead of "save as" current web page?
3. There is no way other than AutoIt to achieve my goal? If so, how to I access the "save as" dialog after it's opened from WebDriver, or I have to open the dialog directly from AutoIt?
Thanks in advance,
C.M.