locked
How do I get to the HTMLDocument from BrowserWindow RRS feed

  • Question

  • I need to be able to get to the HTMLDocument from myBrowserWindow.  I have the following code.

    BrowserWindow mybrowser;
    mybrowser = BrowserWindow.Launch(new Uri(http://www.google.com));
    I see that there is a CurrentDocumentWindow but that doesn't give me the htmldocument. I need it to get 
    GetProperty("OuterHtml") of the HTMLDocument.
    Thanks


    Thursday, August 12, 2010 5:33 PM

Answers

  • You can just search for it under the browser window. The following code should work.

    BrowserWindow window = BrowserWindow.Launch();

    HtmlDocument document = new HtmlDocument(window);

    document.GetProperty("OuterHtml");

    Vinoth.

    Friday, August 13, 2010 9:09 AM

All replies

  • OK, after a lot of digging I found that I could get the Child of the BrowserWindow.CurrentDocumentWindow and that gave me access to the HTMLBody or HTMLDocument and then I was able to get he OuterHtml from GetPerperty.  Is this really that way or is there a better way?

    BrowserWindow mybrowser;
    mybrowser = BrowserWindow.Launch(new Uri(http://www.ancestry.com));
    UITestControlCollection c = mybrowser.CurrentDocumentWindow.GetChildren();
    string b = (string)c[0].GetProperty("OuterHtml");

     

    Thursday, August 12, 2010 11:06 PM
  • You can just search for it under the browser window. The following code should work.

    BrowserWindow window = BrowserWindow.Launch();

    HtmlDocument document = new HtmlDocument(window);

    document.GetProperty("OuterHtml");

    Vinoth.

    Friday, August 13, 2010 9:09 AM
  • This answer is incorrect as there is not now nor has there ever been the ability to new up a HTMLDOCUMENT.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument(v=vs.100).aspx


    JP Cowboy Coders Unite!

    Tuesday, December 18, 2012 8:21 AM
  • My apologies for this post, I found that this namespace does have a CTOR for HTML document...

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.htmlcontrols.aspx

    This is news to me.


    JP Cowboy Coders Unite!

    Tuesday, December 18, 2012 9:22 AM
  • However, please note that the HTMLDOCUMENT in this namespace has little similarity to the DOMDocument!  It is a specific Test Version of the HTMLDOCUMENT has has very few methods associated with traversing the elements etc.

    JP Cowboy Coders Unite!

    Tuesday, December 18, 2012 9:30 AM