tags:

views:

31

answers:

2

I'm trying to save the full content of the current static web page, using the code from http://stackoverflow.com/questions/3546047/show-save-as-dialog-of-ie-using-watin

So here it is:

IE ie = new IE("http://localhost"); // more code

//I expect out.html is the output file FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("out.html");

//I expect this line to popup the save as dialog box, but nothing happens ie.AddDialogHandler(fileDownloadHandler);

//the program is blocked at this line, as it can't click anywhere ie.Link("startDownloadLinkId").Click();

        fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15); 
        fileDownloadHandler.WaitUntilDownloadCompleted(200); 

I also tried the code below, but it doesn't save all the page: System.IO.StreamWriter file = new System.IO.StreamWriter("output.html"); file.Write(ie.Html);

Again, I need to save the webpage from Watin, and the result to be the same as saving it manually.

Thanks!

A: 

Try to parse the html with html agility pack and save it, there are additional abilities that you can use...

        using HtmlAgilityPack;

        var htmldoc = new HtmlDocument();
        htmldoc.LoadHtml(ie.Html);
        htmldoc.Save(stream);

Link to agility pack

alonp
I tried HtmlAgilityPack, but it doesn't work, as it produces the same output as: file.Write(ie.Html). I need to get the same output as from viewing the source code in the browser itself.
xls
A: 

Not sure about WatiN, but with iMacros this is easy: Browser Automation - Saving Websites

iMacros comes in free/open-source and commercial flavors. The free iMacros for Firefox includes good command line support.

FrankJK
Sorry, I'm interested in a Watin approach, as I already have code written using it.
xls