Save Page Source to a File

4 posts, 0 answers
  1. Chris
    Chris avatar
    2 posts
    Member since:
    Aug 2012

    Posted 11 Aug 2012 Link to this post

    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?

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 13 Aug 2012 Link to this post

    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
  3. Chris
    Chris avatar
    2 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Thanks Anthony; this is very helpful.

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

  4. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 14 Aug 2012 Link to this post

    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
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!