How to save current web page automatically with specified directory/filename

265 views
Skip to first unread message

Chris Mathrew

unread,
Feb 17, 2014, 7:13:27 PM2/17/14
to webd...@googlegroups.com

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.

Rakesh Kirola

unread,
Feb 18, 2014, 12:51:08 PM2/18/14
to webd...@googlegroups.com
You can use Robot class to interact with OS dialog.


Best Regards,

Rakesh Kirola


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

darrell

unread,
Feb 19, 2014, 6:49:11 AM2/19/14
to webd...@googlegroups.com
If you are using a local instance of WebDriver, e.g. ChromeDriver, FirefoxDriver, etc. then you are running your code on the same machine as the web browser. You still cannot use WebDriver to save the page but you can use something like Robot or some desktop application automation tool to use the web browser as you would any other desktop application. If you are using RemoteWebDriver then you need some way of controlling desktop automation software on a remote computer.

In other words, you cannot do this with WebDriver. You need to look into using some other tool to do what you want.
Reply all
Reply to author
Forward
0 new messages