This is a migrated thread and some comments may be shown as answers.

Save Page Source to a File

3 Answers 39 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 11 Aug 2012, 03:13 PM
Hi,

I'm new to Telerik and want to do something fairly simple (I think). I want Telerik to bring up a page in the browser and then save the page source to a file. How to do that?

3 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 13 Aug 2012, 07:26 PM
Hello Chris,

First, be aware that you can set a Breakpoint and use the Capture feature from the Visual Debugger to save a snapshot of the DOM.

To automate this takes just a few lines of code:

string dom = ActiveBrowser.ViewSourceString;
 
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\temp\dom.txt");
file.WriteLine(dom);
file.Close();

If you prefer Visual Basic use our code converter.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Chris
Top achievements
Rank 1
answered on 14 Aug 2012, 03:47 AM
Thanks Anthony; this is very helpful.

How would I access the source from within an iframe on the page?

0
Anthony
Telerik team
answered on 14 Aug 2012, 01:34 PM
Hello Chris,

The same way as before, but you must identify the frame first. See our Frames Support page for more information.

Here's an example against this W3 Schools demo site:

ArtOfTest.WebAii.Core.Browser frSub = ActiveBrowser.Frames["view"];
string dom = frSub.ViewSourceString;
 
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\temp\dom.txt");
file.WriteLine(dom);
file.Close();


Regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Chris
Top achievements
Rank 1
Share this question
or